return.php
<?php
define('ABS_PATH', dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))) . '/');
require_once ABS_PATH . 'oc-load.php';
$MerchantID = payment_pro_decrypt(osc_get_preference('zarinpal_merchant_id', 'payment_pro')); //Required
$rpl = $_GET['rpl'];
$data = payment_pro_get_custom($rpl);
$Amount = $data['amount']/10;
$Authority = $_GET['Authority'];
$currency = osc_get_preference('currency', 'payment_pro');
if($_GET['Status'] == 'OK'){
if(osc_get_preference('zarinpal_sandbox','payment')==1) {
$client = new SoapClient('https://sandbox.zarinpal.com/pg/services/WebGate/wsdl', ['encoding' => 'UTF-8']);
}else{
$client = new SoapClient('https://www.zarinpal.com/pg/services/WebGate/wsdl', ['encoding' => 'UTF-8']);
}
$result = $client->PaymentVerification(
array(
'MerchantID' => $MerchantID,
'Authority' => $Authority,
'Amount' => $Amount
)
);
if($result->Status == 100){
$exists = ModelPaymentPro::newInstance()->getPaymentByCode($result->RefID, 'ZARINPAL');
if(isset($exists['pk_i_id'])) {
$message = 'Previously paid';
}elseif (!$exists['pk_i_id']) {
$payment_id = ModelPaymentPro::newInstance()->saveInvoice(
$result->RefID, // transaction code
$data['amount'], //amount
'10',
$data['amount'],
$currency,
$data['email'],
$data['user'],
'ZARINPAL',
$data['itemid']
);
$message = 'Payment completed <br/> Payment Receipt Number: ' . $result->RefID;
if($status==PAYMENT_PRO_COMPLETED) {
foreach($data['items'] as $item) {
$tmp = explode("-", $item['id']);
$item['item_id'] = $tmp[count($tmp) - 1];
osc_run_hook('payment_pro_item_paid', $item, $data, $invoiceId);
}
}
}
} else {
$message = 'Error in validating payment! Error status: '.$result->Status;
}
} else {$message='Payment has been canceled by the user.';}
osc_add_flash_ok_message($message);
payment_pro_js_redirect_to(osc_route_url('payment-pro-checkout'));
?>