Advertisement:

Author Topic: HELP ME: Payment Pro- Iranian payment service - ZarinPal  (Read 535 times)

abc500x500

  • Jr. Member
  • **
  • Posts: 96
HELP ME: Payment Pro- Iranian payment service - ZarinPal
« on: December 24, 2018, 02:17:52 pm »
Hi.
I want to create a payment for payment pro plugin.

In Iran famous easy to obtain bank creditcard payment is ZARINPAL.

https://www.zarinpal.com

Please help and if there is a documentation about "Osclass Payment Pro" please say me.
Please Help.
Thanks

abc500x500

  • Jr. Member
  • **
  • Posts: 96
Re: HELP ME: Payment Pro- Iranian payment service - ZarinPal
« Reply #1 on: December 24, 2018, 02:23:06 pm »

abc500x500

  • Jr. Member
  • **
  • Posts: 96
Re: HELP ME: Payment Pro- Iranian payment service - ZarinPal
« Reply #2 on: December 24, 2018, 02:28:33 pm »
This is an example that zarinpal in its website show:
https://www.zarinpal.com/lab/%d9%86%d9%85%d9%88%d9%86%d9%87-%da%a9%d8%af-%d8%a7%d8%b3%d8%aa%d9%81%d8%a7%d8%af%d9%87-%d9%88%d8%a8-%d8%b3%d8%b1%d9%88%d9%8a%d8%b3-%d9%86%d9%88%d8%b4%d8%aa%d9%87-%d8%b4%d8%af%d9%87-%d8%a8/

Send.php
Code: [Select]

<?php
//send.php
$MerchantID 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'//Required
$Amount 1000//Amount will be based on Toman - Required
$Description 'Description'// Required
$Email 'UserEmail@Mail.Com'// Optional
$Mobile '09123456789'// Optional
$CallbackURL 'http://www.yoursoteaddress.ir/verify.php'// Required


$client = new SoapClient('https://www.zarinpal.com/pg/services/WebGate/wsdl', ['encoding' => 'UTF-8']);

$result $client->PaymentRequest(
[
'MerchantID' => $MerchantID,
'Amount' => $Amount,
'Description' => $Description,
'Email' => $Email,
'Mobile' => $Mobile,
'CallbackURL' => $CallbackURL,
]
);

//Redirect to URL You can do it also by creating a form
if ($result->Status == 100) {
Header('Location: https://www.zarinpal.com/pg/StartPay/'.$result->Authority);
//If use zaringate change address to this:
//Header('Location: https://www.zarinpal.com/pg/StartPay/'.$result->Authority.'/ZarinGate');
} else {
echo
'ERR: '.$result->Status;
}



Verify.php
Code: [Select]
<?php
$MerchantID 
'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX';
$Amount 1000//Amount will be based on Toman
$Authority $_GET['Authority'];

if (
$_GET['Status'] == 'OK') {

$client = new SoapClient('https://www.zarinpal.com/pg/services/WebGate/wsdl', ['encoding' => 'UTF-8']);

$result $client->PaymentVerification(
[
'MerchantID' => $MerchantID,
'Authority' => $Authority,
'Amount' => $Amount,
]
);

if (
$result->Status == 100) {
echo 
'Transaction success. RefID:'.$result->RefID;
} else {
echo 
'Transaction failed. Status:'.$result->Status;
}
} else {
echo 
'Transaction canceled by user';
}
?>


abc500x500

  • Jr. Member
  • **
  • Posts: 96
Re: HELP ME: Payment Pro- Iranian payment service - ZarinPal
« Reply #3 on: December 24, 2018, 02:37:44 pm »
I found a free payment codes that an Iranian had written for Osclass but that not for payment pro.
I changed that files it go to payment gate and pay by cart in gate success but in return it do not work and my code show error:
Quote
Transaction failed.
.

ZarinpalPayment.php
Code: [Select]
<?php
     
class ZarinpalPayment implements iPayment
    
{

        public function 
__construct()
        {
        }

           public static function 
button($products$extra null) {

           
$amount 0;
            foreach(
$products as $p) {
                
$amount += $p['amount']*$p['quantity']*((100+$p['tax'])/100);
            }

            
$r rand(0,1000);
            
$extra['random'] = $r;
            
$extra['items'] = $products;
            
$extra['amount'] = $amount;
            
$extra payment_pro_set_custom($extra);
            
            
$tx_id ModelPaymentPro::newInstance()->pendingInvoice($products30);
           
$order_id $tx_id;

            echo 
'<li class="payment zarinpal-btn">';

            
$action PAYMENT_PRO_URL.'payments/zarinpal/send.php';
        
?>

            <form action="<?php echo $action?>" method="post" id="zarinpal_<?php echo $r?>">
              <input type="hidden" name="amount" value="<?php echo $amount?>" />
              <input type="hidden" name="custom" value="<?php echo $extra?>" />
            </form>
            <div class="buttons">
              <div class="right"><a id="button-confirm" class="button" onclick="$('#zarinpal_<?php echo $r?>').submit();"><span><img src='<?php echo PAYMENT_PRO_URL?>payments/zarinpal/images/zarinpal.gif' border='0' /></span></a></div>
            </div>
        <?php


            
echo '</li>';
        }
                    public static function 
recurringButton($products$extra null) {}

                    public static function 
processPayment() { }
}
    

?>


abc500x500

  • Jr. Member
  • **
  • Posts: 96
Re: HELP ME: Payment Pro- Iranian payment service - ZarinPal
« Reply #4 on: December 24, 2018, 02:42:47 pm »
send.php

Code: [Select]

<?php
define
('ABS_PATH'dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))) . '/');
require_once 
ABS_PATH 'oc-load.php';

    
$return $_POST['custom'];
    
$Amount $_POST['amount']/10;
    
$return .= "|".$Amount;
    
$data payment_pro_set_custom($return);
$MerchantID payment_pro_decrypt(osc_get_preference('zarinpal_merchant_id''payment_pro'));   //Required

    
$Description '?';  // Required Please say how to use to description about product in this file.
     
$Email 'info@site.Com'//  Please say how to use email of USER of OSCLASS in this file.
$Mobile ='0123456789'// Please say how to use phone of USER of OSCLASS in this file.

$callBackUrl PAYMENT_PRO_URL.'payments/zarinpal/return.php?rpl=' $return;

    if(
osc_get_preference('zarinpal_sandbox','payment_pro')==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->PaymentRequest(
array(
'MerchantID'  => $MerchantID,
'Amount'      => $Amount,
'Description'  => $Description,
'Email'      => $Email,
'Mobile'      => $Mobile,
'CallbackURL'  => $callBackUrl
)
);

if($result->Status == 100)
{
        if(
osc_get_preference('zarinpal_sandbox','payment')==1) {
            
header('Location: https://sandbox.zarinpal.com/pg/StartPay/'.$result->Authority);
        }else{
            
header('Location: https://www.zarinpal.com/pg/StartPay/'.$result->Authority);
        }
}

    switch(
$result->Status) {
        case 
'-1':
        
osc_add_flash_ok_message("Information is Incomplete");
        
payment_pro_js_redirect_to(osc_route_url('payment-pro-checkout'));
        
        break;
        case 
'-2':
        
osc_add_flash_ok_message('IP or merchant id is false.');
        
payment_pro_js_redirect_to(osc_route_url('payment-pro-checkout'));
        break;
        case 
'-3':
        
osc_add_flash_ok_message('This amount price is forbidden.');
        
payment_pro_js_redirect_to(osc_route_url('payment-pro-checkout'));
        break;
        case 
'-4':
        
osc_add_flash_error_message('under silver level.');
        
payment_pro_js_redirect_to(osc_route_url('payment-pro-checkout'));
        break;
    }

?>


« Last Edit: December 24, 2018, 03:03:18 pm by abc500x500 »

abc500x500

  • Jr. Member
  • **
  • Posts: 96
Re: HELP ME: Payment Pro- Iranian payment service - ZarinPal
« Reply #5 on: December 24, 2018, 03:19:00 pm »
return.php

Code: [Select]

<?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'));

?>


« Last Edit: December 24, 2018, 03:28:40 pm by abc500x500 »

abc500x500

  • Jr. Member
  • **
  • Posts: 96
Re: HELP ME: Payment Pro- Iranian payment service - ZarinPal
« Reply #6 on: December 24, 2018, 03:27:21 pm »
I have changed that zarinpal payment  for Osclass Payment Pro.
I inserted my codes in previous posts in this topic.

I added this payment files to this topic.
Please Help.
Thanks
« Last Edit: December 24, 2018, 03:29:48 pm by abc500x500 »

abc500x500

  • Jr. Member
  • **
  • Posts: 96
Re: HELP ME: Payment Pro- Iranian payment service - ZarinPal
« Reply #7 on: December 24, 2018, 07:58:46 pm »
one of problems is:

After verify bank transaction, how it should insert data to database?

For example products.php is a file that codes for inserting data t DB after payment are there.

abc500x500

  • Jr. Member
  • **
  • Posts: 96
Re: HELP ME: Payment Pro- Iranian payment service - ZarinPal
« Reply #8 on: December 25, 2018, 08:32:33 pm »
How i can save these in database?
how i can send  these info to payment_pro/payments/zarinpal/ZarinpalPayment.php ?
please see image.
Code PUB103-61
Product  Publish fee for item 61
Quantity

***********************

2) Also If unregistered user buy an item; How i can sent his email and user and phone to payment_pro/payments/zarinpal/ZarinpalPayment.php ?

Please help.
Thanks