Commit ed1f74b6 authored by Ifaliana Arimanana's avatar Ifaliana Arimanana
Browse files

Merge remote-tracking branch 'origin/qa' into qa

parents cce546c1 716b4a12
......@@ -2,7 +2,6 @@
/**
* PaymentController.php
*
*
* @author: Dady Christon <devchriston@gmail.com>
* Date: 26/02/2021
*/
......@@ -12,78 +11,110 @@ class PaymentController extends CommunecterController {
return parent::beforeAction($action);
}
public function actionPay(){
public function actionPay($orga, $mode){
$mollie = new \Mollie\Api\MollieApiClient();
$parent = PHDB::findOneById("organizations", $orga);
if(isset($parent["mollie_key_$mode"]) && !empty($parent["mollie_key_$mode"])){
$mollie->setApiKey($parent["mollie_key_$mode"]);
# $mollie->setAccessToken("Here is token if needed");
$orderId = time();
$protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http";
$hostname = $_SERVER['HTTP_HOST'];
$path = dirname(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF']);
$payment_data = [
"amount" => [
"currency" => "EUR",
"value" => $_POST["amount"]["value"]
],
"description" => $_POST["description"],
"redirectUrl" => "{$protocol}://{$hostname}{$path}/check/?order_id={$orderId}&source={$_POST['source']}&page={$_POST['page']}",
"webhookUrl" => "{$protocol}://{$hostname}{$path}/check/?order_id={$orderId}&source={$_POST['source']}&page={$_POST['page']}",
"metadata" => [
"order_id" => $orderId,
]
];
if($mode=="test"){
$payment_data["method"] = "creditcard";
}
$mollie->setApiKey("test_t7D34dypCf67SrtJDb4QN5xNETpB3a");
# $mollie->setAccessToken("Here is token if needed");
$orderId = time();
$protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http";
$hostname = $_SERVER['HTTP_HOST'];
$path = dirname(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF']);
$payment = $mollie->payments->create([
"amount" => [
"currency" => "EUR",
"value" => $_POST["amount"]["value"]
],
"description" => $_POST["description"],
"method" => "creditcard",
"redirectUrl" => "{$protocol}://{$hostname}{$path}/check/?order_id={$orderId}&form={$_POST['form']}&page={$_POST['page']}",
"webhookUrl" => "{$protocol}://{$hostname}{$path}",
"metadata" => [
"order_id" => $orderId,
],
]);
# insert payment infos to database
PHDB::insert("payments",
array(
'payment' => array(
'id' => $payment->id,
'currency' => "EUR",
'value' => $_POST["amount"]["value"],
'description' => $_POST["description"],
'nbPart' => $_POST["nbPart"],
'isPaid' => false
),
'user' => $_SESSION["userId"],
'source' => array('form' => $_POST["form"]),
'orderId' => "$orderId"
)
);
return Rest::json(array('url' => $payment->getCheckoutUrl()));
$payment = $mollie->payments->create();
# Keep payment in database
PHDB::insert("payments",
array(
'payment' => array(
'id' => $payment->id,
'currency' => "EUR",
'value' => $_POST["amount"]["value"],
'description' => $_POST["description"],
'nbPart' => $_POST["nombre"],
'isPaid' => false
),
'collection' => 'payments',
'user' => $_SESSION["userId"],
'parent' => array('id' => $orga),
'source' => array(
'key' => (isset($_POST["form"]))?$_POST["form"]:"",
),
'orderId' => "$orderId",
'mode' => "$mode"
)
);
return Rest::json(array('url' => $payment->getCheckoutUrl()));
}else{
return Rest::json(array('message' => "Vous n'avez pas les condition nécessaire pour utiliser cette fonctionnalité"));
}
}
# Check if payment is paid
public function actionCheck($order_id, $form, $page){
public function actionCheck($order_id, $source, $page){
$mollie = new \Mollie\Api\MollieApiClient();
$mollie->setApiKey("test_t7D34dypCf67SrtJDb4QN5xNETpB3a");
# $mollie->setAccessToken("Here is token if needed"); 0340287138
$p = PHDB::findOne("payments", array('orderId' => "$order_id"));
if(isset($p["payment"]["id"])){
$payment = $mollie->payments->get($p["payment"]["id"]);
if ($payment->isPaid()){
$res = array('isPaid' => true);
PHDB::update("payments", array('orderId' => "$order_id"), array('$set' => array('payment.isPaid' => true)));
PHDB::update("answers", array('user' => $_SESSION["userId"], 'form' => "$form"), array('$set' => array('answers.isPaid' => true)));
$parent = PHDB::findOneById("organizations", $p["parent"]["id"]);
if(isset($parent["mollie_key_".$p["mode"]]) && !empty($parent["mollie_key_".$p["mode"]])){
$mollie->setApiKey($parent["mollie_key_".$p["mode"]]);
if(isset($p["payment"]["id"])){
$payment = $mollie->payments->get($p["payment"]["id"]);
if ($payment->isPaid()){
$res = array('isPaid' => true);
PHDB::update("payments", array('orderId' => "$order_id"), array('$set' => array('payment.isPaid' => true)));
$source = PHDB::count("answers", array('form' => $source));
if($source > 0){
PHDB::update("answers", array('user' => $_SESSION["userId"], 'form' => "$source"), array('$set' => array('answers.isPaid' => true)));
}
}else{
$res = array('isPaid' => false);
}
}else{
$res = array('isPaid' => false);
$res = array('isPaid' => false);
}
return $this->redirect("$page");
}else{
$res = array('isPaid' => false);
return Rest::json(array('message' => "Payement invalide"));
}
}
return $this->redirect("$page");
public function actionGetPaymentMethode()
{
$payment_methode = array();
return Rest::json($payment_methode);
}
public function actionInvoice($id, $slug, $user=null, $form=null) {
......
......@@ -256,20 +256,25 @@
},
"description": "Droit d'associé en tant que "+st.type+" à titre de "+st.label,
"page": window.location.href,
"form": "<?=$answer["form"]?>",
"nbPart": $("#nbPart").val()
"source": "<?=$answer["form"]?>",
"nombre": $("#nbPart").val()
}
$.ajax({
url: '<?= Yii::app()->baseUrl; ?>/survey/payment/pay',
type: 'POST',
data: paymentData,
dataType: "json"
}).done(function(data){
location = data.url;
}).fail(function(xhr,textStatus,errorThrown,data){
toastr.error("Une erreur s'est produite, veuillez signaler ce problème à notre administrateur");
});
ajaxPost(
null,
'<?= Yii::app()->baseUrl; ?>/survey/payment/pay?orga=<?= $this->costum["contextId"]; ?>&mode=test',
paymentData,
function(data){
if(data.url){
location = data.url;
}
if(data.message){
toastr.error(data.message);
}
},
function(xhr,textStatus,errorThrown,data){
toastr.error("Une erreur s'est produite, veuillez signaler ce problème à notre administrateur");
}, 'json');
}else{
toastr.warning("Veuillez remplir toutes avant de payer votre droit d'associé")
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment