Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
add remote files
Browse files Browse the repository at this point in the history
  • Loading branch information
afatsini committed Aug 12, 2016
1 parent 98f1ff7 commit dc1138c
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ protected function getFormFields()
'merchant_loan_id' => $merchant_loan_id,
'success_url' => $ok_url,
'failure_url' => $nok_url,
'postback_url' => $callback_url,
'postback_url' => 'https://demoshop.pagamastarde.com/getfinancing/xcart/callback.php',
'software_name' => 'x-cart',
'software_version' => 'xcart 5'
);
Expand Down
50 changes: 50 additions & 0 deletions remote/xcart/callback.php
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.");
}
?>

65 changes: 65 additions & 0 deletions remote/xcart/redirect.php
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>


0 comments on commit dc1138c

Please sign in to comment.