This repository has been archived by the owner on Aug 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/* | ||
to be placed at: https://demoshop.pagamastarde.com/getfinancing/xcart/callback.php | ||
*/ | ||
require_once ("config.php"); | ||
//recevice original pmt notification | ||
$json = file_get_contents('php://input'); | ||
$temp = json_decode($json,true); | ||
|
||
if ( $temp['updates']['status'] == "approved" || $temp['updates']['status'] == "preapproved"){ | ||
|
||
//recover all saved data form the order | ||
$db = mysqli_init(); | ||
$link = $db->real_connect ($db_host, $db_username,$db_password,$db_name); | ||
if (!$link) | ||
{ | ||
throw new Exception('Connect error (' . mysqli_connect_errno() . '): ' . mysqli_connect_error() . "\n"); | ||
} | ||
$db->set_charset("utf8"); | ||
$sql="SELECT * FROM `payments_gf` where trx_id = '".$temp['merchant_transaction_id']."' order by id desc limit 1"; | ||
echo $sql; | ||
if ($result = $db->query($sql)) { | ||
if ($myrow = $result->fetch_array(MYSQLI_ASSOC)) { | ||
$data =$myrow; | ||
} | ||
}else{ | ||
throw new Exception("SQL error ".$db->error); | ||
} | ||
if ($temp['updates']['status'] == "approved"){ | ||
$x_result="completed"; | ||
}else{ | ||
$x_result="pending"; | ||
} | ||
//send the callback to Shopty to confirm the purchase | ||
$curl = curl_init(); | ||
curl_setopt($curl, CURLOPT_URL, $data['callback_url']); | ||
curl_setopt($curl, CURLOPT_POST, true); | ||
curl_setopt($curl, CURLOPT_POSTFIELDS, $json); | ||
curl_setopt($curl, CURLOPT_TIMEOUT, 30); | ||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false); | ||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | ||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); | ||
curl_exec($curl); | ||
curl_close($curl); | ||
}else{ | ||
die("Status is not approved, aborting."); | ||
} | ||
?> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
/* | ||
to be placed at: https://demoshop.pagamastarde.com/getfinancing/xcart/redirect.php | ||
*/ | ||
|
||
require('config.php'); | ||
$callback_url = $_POST['callback_url']; | ||
$success_url= $_POST['success_url']; | ||
$failure_url = $_POST['failure_url']; | ||
$form_url = $_POST['form_url']; | ||
$trx_id = $_POST['trx_id']; | ||
|
||
if (empty($form_url)){ | ||
header("Location: $failure_url"); | ||
} | ||
|
||
//in order to send proper values of the callback, we need to save values in database to grab it on return. | ||
$db = mysqli_init(); | ||
$link = $db->real_connect ($db_host, $db_username,$db_password,$db_name); | ||
if (!$link) | ||
{ | ||
throw new Exception ('Connect error (' . mysqli_connect_errno() . '): ' . mysqli_connect_error() . "\n"); | ||
} | ||
$db->set_charset("utf8"); | ||
$sql="INSERT INTO `xcart_gf`.`payments_gf` (`ID`, `insert_date`, `callback_url`, `success_url`, `failure_url`, `form_url`, `trx_id` ) VALUES | ||
(NULL, | ||
CURRENT_TIMESTAMP, | ||
'".$callback_url."', | ||
'".$success_url."', | ||
'".$failure_url."', | ||
'".$form_url."', | ||
'".$trx_id."')"; | ||
if ($db->query($sql) === TRUE) { | ||
|
||
}else{ | ||
throw new Exception("SQL error ".$db->error); | ||
} | ||
|
||
|
||
?> | ||
<!-- automatically redirect to pmt --> | ||
Thank you for your order! Follow the GetFinancing process to finish the payment. | ||
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script> | ||
<script src="https://partner.getfinancing.com/libs/1.0/getfinancing.js"></script> | ||
|
||
<script> | ||
var onComplete = function() { | ||
// this is called when the user finishes all the steps and | ||
window.location.href='<?php echo $success_url; ?>'; | ||
}; | ||
|
||
var onAbort = function() { | ||
// this is called when the user closes the lightbox before | ||
window.location.href='<?php echo $success_url; ?>'; | ||
}; | ||
|
||
setTimeout(function(){ | ||
new GetFinancing( '<?php echo $form_url; ?>' , onComplete, onAbort); | ||
},2000); // 2000 is the delay in milliseconds | ||
|
||
|
||
|
||
</script> | ||
|
||
|