Hello,
I've problem with payment extension. I'm making bank payment extension I send request to bank but can't get/check callback ...
Please help
I'll attach bank requirements.
Here is Code:
Code: Select all
public function index(){
$this->load->model('checkout/order');
$this->load->model('catalog/product');
$this->language->load('extension/payment/atbaz');
$data['button_confirm'] = $this->language->get('button_confirm');
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
$products = $this->cart->getProducts();
//START MY CODE
$url = 'https://epgtest.azerturkbank.az/epg/ibus/atbecomm/v1/pay/init';
// Create a new cURL resource
$ch = curl_init($url);
//If you will want ro test here is mrchId=>5120001 password=>vostok_d_rv
$sdata = array( 'header' =>[
'mrchId' => $this->config->get('atbaz_merchant_id'),
'password' => $this->config->get('atbaz_password')],
'currencyCode'=>'944',
'mrchSuccessUrl'=>'http://vostok.az/index.php?route=checkout/success&',
'mrchFailUrl'=>'http://vostok.az/index.php?route=checkout/failure&',
'mrchServiceUrl'=>'http://vostok.az/index.php?route=extension/payment/atbaz/callback&',
'amount'=>$order_info['total'],
'transactionId'=>$order_info['order_id']."_".rand(1,999),
'subpayments'=>$this->AzprodData($products)
);
$payload = json_encode($sdata);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
// Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
// Return response instead of outputting
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute the POST request
$result = curl_exec($ch);
$result = json_decode($result);
$curlsuccess = false;
$curlerror = false;
if (array_key_exists("orderId",$result))
{
$orderid = $result->orderId;
$curlsuccess = $result->formUrl;
}
elseif(array_key_exists("errorCode",$result))
{
$curlerror = $result->errorData;
}
else{
}
// Close cURL resource
curl_close($ch);
//END MY CODE
$data['sdata'] = $payload;
$data['err'] = $curlerror;
$data['csucc'] = $curlsuccess;
$data['action'] = 'https://epgtest.azerturkbank.az/epg/ibus/atbecomm/v1/pay/init';
return $this->load->view('extension/payment/atbaz', $data);
}
//START MY HELPER FUNCTION
private function AzprodData($products){
$return = "";
$a_product = "";
$b_product = "";
$SUM = 0;
$arr = array();
foreach($products as $i => $product){
$Name = $product['name'];
$Quantity = $product['quantity'];
$Price = $product['price'];
$SUMPrice = $product['total'];
$SUM += $SUMPrice;
$NewName = $Quantity." x ".$Name;
$a_product .= $NewName.$SUMPrice;
$b_product .= '<input type="hidden" name="item'.($i+1).'_name" value="'.$NewName.'" />';
$b_product .= '<input type="hidden" name="item'.($i+1).'_price" value="'.$SUMPrice.'" />';
$arr[] = ['description'=>$NewName, 'amount'=>$SUMPrice];
}
return $arr;
}
//END MY HELPER FUNCTION
//CALLBACK FUNCTION
public function callback()
{
$this->load->model('checkout/order');
$this->load->language('extension/payment/atbaz');
$returnStatus = 0;
$resultMessage = '';
$returnCheck = "";
$payedamount = 0;
if (isset($this->request->post['transactionId'])){
$transactioncode = $this->request->post['transactionId'];
}else{
$transactioncode = '';
}
$password = $this->config->get('atbaz_password');
if (isset($this->request->post['rrn'])) {
$status = "COMPLETED";
$transactionId = $this->request->post['transactionId'];
$amount = $this->request->post['amount'];
$rrn = $this->request->post['rrn'];
$errorCode =$this->request->post['errorCode'];
if ($status == 'COMPLETED') {
$this->model_checkout_order->addOrderHistory($ordercode, $this->config->get('atbaz_order_status_id'));
$returnStatus = "0";
$resultMessage = "Seccess";
} else {
$returnStatus = "-3";
$resultMessage = "Param Error";
}
} else {
$returnStatus = "-1";
$resultMessage = "Technical Problem";
}
//START MY CODE
$url = 'https://epgtest.azerturkbank.az/epg/ibus/atbecomm/v1/pay/init';
// Create a new cURL resource
$ch = curl_init($url);
$sdata = array(
'transactionId'=>$transactionId,
'mrchRrn'=>$rrn,
'errorCode'=>'0');
$payload = json_encode($sdata);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
// Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
// Return response instead of outputting
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute the POST request
$result = curl_exec($ch);
// Close cURL resource
curl_close($ch);
}
Nobody will read the API documentation and your code for free. Post a request in Commercial Support forum instead.
Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com
Who is online
Users browsing this forum: No registered users and 22 guests