Skip to content

Commit 4b95941

Browse files
authored
Merge pull request #83 from Hystepik/New-add-test-for-payment-verification
New add test for payment verification after payment for Stancer DoliCloud
2 parents e0839c0 + cbe2364 commit 4b95941

File tree

1 file changed

+57
-13
lines changed

1 file changed

+57
-13
lines changed

htdocs/stancerdolicloud/class/actions_stancerdolicloud.class.php

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,9 @@ public function isPaymentOK($parameters, &$object, &$action, $hookmanager)
558558
{
559559
global $langs;
560560

561+
require_once DOL_DOCUMENT_ROOT."/core/lib/geturl.lib.php";
562+
include_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
563+
561564
$error = 0; // Error counter
562565
$ispaymentok = false;
563566

@@ -568,21 +571,62 @@ public function isPaymentOK($parameters, &$object, &$action, $hookmanager)
568571
$ispaymentok = false;
569572
$error ++;
570573
} else {
571-
// TODO Do a check with payplug api call
572-
573-
574-
575-
$ispaymentok = true;
574+
$stancerurlapi = "api.stancer.com";
575+
$stancerurlpayment = "payment.stancer.com";
576+
if (getDolGlobalInt("STANCER_DOLICLOUD_LIVE")) {
577+
$secretapikey = getDolGlobalString("STANCER_DOLICLOUD_PROD_SECRET_API_KEY");
578+
} else {
579+
$secretapikey = getDolGlobalString("STANCER_DOLICLOUD_TEST_SECRET_API_KEY");
580+
}
581+
$encodedkey = dol_encode($secretapikey, 0);
582+
$headers = array();
583+
$headers[] = "accept: application/json";
584+
$headers[] = "Authorization: Basic ".$encodedkey;
585+
$headers[] = "Content-Type: application/json";
586+
587+
$FinalPaymentID = $_SESSION["STANCER_DOLICLOUD_PAYMENT_ID"];
588+
$urlforcheckout = "https://".urlencode($stancerurlapi)."/v2/payment_intents/".$FinalPaymentID;
589+
dol_syslog("Send Get to url=".$urlforcheckout." with session STANCER_DOLICLOUD_PAYMENT_ID = ".$FinalPaymentID, LOG_DEBUG);
590+
$ret1 = getURLContent($urlforcheckout, 'GET', "", 1, $headers);
591+
if ($ret1["http_code"] == 200) {
592+
$result1 = $ret1["content"];
593+
$json = json_decode($result1);
594+
if (in_array($json->status, array("captured", "authorized", "capture_sent", "to_capture"))) {
595+
$ispaymentok = true;
596+
}
597+
} else {
598+
$arrayofmessage = array();
599+
if (!empty($ret1['content'])) {
600+
$arrayofmessage = json_decode($ret1['content'], true);
601+
}
602+
if (!empty($arrayofmessage['message'])) {
603+
$this->errors[] = $arrayofmessage['message'];
604+
} else {
605+
if (!empty($arrayofmessage['errors']) && is_array($arrayofmessage['errors'])) {
606+
foreach($arrayofmessage['errors'] as $tmpkey => $tmpmessage) {
607+
if (!empty($tmpmessage['message'])) {
608+
$this->errors[] = $langs->trans("Error").' - '.$tmpmessage['message'];
609+
} else {
610+
$this->errors[] = $langs->trans("UnkownError").' - HTTP code = '.$ret1["http_code"];
611+
}
612+
}
613+
} else {
614+
$this->errors[] = $langs->trans("UnkownError").' - HTTP code = '.$ret1["http_code"];
615+
}
616+
}
617+
$error++;
618+
$ispaymentok = false;
619+
}
620+
}
621+
if (!$error) {
622+
$this->results["ispaymentok"] = $ispaymentok;
623+
return 1;
624+
} else {
625+
$this->errors[] = $langs->trans("PaymentRefused");
626+
return -1;
576627
}
577628
}
578-
579-
if (!$error) {
580-
$this->results["ispaymentok"] = $ispaymentok;
581-
return 1;
582-
} else {
583-
$this->errors[] = $langs->trans("PaymentRefused");
584-
return -1;
585-
}
629+
return 0;
586630
}
587631

588632
/**

0 commit comments

Comments
 (0)