selimppc

Zip-pay for production

Dec 21st, 2016
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.77 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: selimreza
  5.  * Date: 6/17/16
  6.  * Time: 2:36 PM
  7.  */
  8.  
  9. namespace App\Helpers;
  10.  
  11. use App\Helpers\TntEnquiry;
  12. use App\Product;
  13. use DOMDocument;
  14. use DateTimeZone;
  15. use DateTime;
  16. use zipMoney;
  17. use zipMoney\Request\Version;
  18. use Illuminate\Support\Facades\DB;
  19.  
  20.  
  21. #use Faker\Provider\DateTime;
  22.  
  23. class ZipPay
  24. {
  25.     /**
  26.      * @param $invoice_number
  27.      * @param $order_head
  28.      * @param $order_detail
  29.      * @param $customer_data
  30.      * @param $delivery_data
  31.      * @throws zipMoney\Exception
  32.      */
  33.     public static function call_to_server($invoice_number, $order_head, $order_detail, $customer_data, $delivery_data)
  34.     {
  35.  
  36.         /*
  37.         SANDBOX
  38.             Merchant ID: 3075
  39.             API Signature: TRjrjwZSprkucEtpL9BNOZPpkjydDIAk0Rlh7iYYbc0=
  40.             Unique Id: daef00bf-536f-41b2-9bc7-2f1a47fc1742
  41.          */
  42.  
  43.         zipMoney\Configuration::$merchant_id  = 3075; //sandbox;
  44.         zipMoney\Configuration::$merchant_key = 'TRjrjwZSprkucEtpL9BNOZPpkjydDIAk0Rlh7iYYbc0='; //sandbox
  45.         zipMoney\Configuration::$environment  = 'sandbox'; //sandbox;
  46.  
  47.  
  48.  
  49.         # Initialize the checkout
  50.        $checkout = new \zipMoney\Api\Checkout();
  51.  
  52.         $checkout->request->charge = true;
  53.         $checkout->request->currency_code = "AUD";
  54.         $checkout->request->txn_id = false;
  55.         $checkout->request->order_id =  $invoice_number; //$this->_current_order_id;
  56.         $checkout->request->in_store = false;
  57.  
  58.         $checkout->request->cart_url    = "http://asimstoys.com.au/mycart";
  59.         $checkout->request->success_url = "http://asimstoys.com.au/redirect_e_way_d/".$invoice_number."/".$order_head->net_amount."/".$customer_data->id ;
  60.        
  61.         $checkout->request->cancel_url  = "http://asimstoys.com.au/redirect_e_way_d/zip-pay-cancel/".$invoice_number;
  62.         $checkout->request->error_url   = "http://asimstoys.com.au/redirect_e_way_d/zip-pay-error/".$invoice_number;
  63.         $checkout->request->refer_url   = "http://asimstoys.com.au/redirect_e_way_d/zip-pay-refer/".$invoice_number;
  64.         $checkout->request->decline_url = "http://asimstoys.com.au/redirect_e_way_d/zip-pay-decline/".$invoice_number;
  65.  
  66.         // Order Info
  67.         $order = new \zipMoney\Request\Order;
  68.         $order->id = $invoice_number or null;
  69.         $order->tax = 0;
  70.         $order->shipping_tax = 0;
  71.         $order->shipping_value = 0;
  72.         $order->total = $order_head->net_amount + $order->shipping_value;
  73.  
  74.         // Order Item 1
  75.         foreach ($order_detail as  $value)
  76.         {
  77.  
  78.             $order_item = new \zipMoney\Request\OrderItem;
  79.             $product = $customer_data = DB::table('product')->where('id',$value->product_id)->first();
  80.             $order_item->id = $value->product_id;
  81.             $order_item->sku  = $product->slug;
  82.             $order_item->name = $product->title;
  83.             $order_item->price =  $value->price;
  84.             $order_item->quantity = $value->qty;
  85.             $order_item->image_url = 'http://asimstoys.com.au/'.$product->image;
  86.  
  87.             $order->detail[] = $order_item;
  88.         }
  89.  
  90.  
  91.         $checkout->request->order = $order;
  92.  
  93.         // Billing Address
  94.         $billingAddress  = new \zipMoney\Request\Address;
  95.  
  96.  
  97.         $billingAddress->first_name = isset($customer_data->first_name)?$customer_data->first_name : null;
  98.         $billingAddress->last_name = isset($customer_data->first_name)?$customer_data->first_name : null;
  99.         $billingAddress->line1 = isset($customer_data->first_name)?$customer_data->first_name : null;
  100.         $billingAddress->line2 = isset($customer_data->suburb)?$customer_data->suburb : null;
  101.         $billingAddress->country = isset($customer_data->country)?$customer_data->country : null;
  102.         $billingAddress->zip = isset($customer_data->postcode)?$customer_data->postcode : null;
  103.         $billingAddress->city = isset($customer_data->state)?$customer_data->state : null;
  104.         $billingAddress->state = isset($customer_data->state)?$customer_data->state : null;
  105.  
  106.         $checkout->request->billing_address  = $billingAddress;
  107.  
  108.         // Shipping Address
  109.         $shippingAddress = new \zipMoney\Request\Address;
  110.  
  111.         $shippingAddress->first_name = isset($delivery_data->first_name)?$delivery_data->first_name : null;
  112.         $shippingAddress->last_name = isset($delivery_data->first_name)?$delivery_data->first_name:null;
  113.         $shippingAddress->line1 = isset($delivery_data->first_name)? $delivery_data->first_name : null;
  114.         $shippingAddress->line2 = isset($delivery_data->suburb)?$delivery_data->suburb : null;
  115.         $shippingAddress->country = isset($delivery_data->country ) ? $delivery_data->country : null;
  116.         $shippingAddress->zip = isset($delivery_data->postcode) ?$delivery_data->postcode : null;
  117.         $shippingAddress->city = isset($delivery_data->state) ?$delivery_data->state : null;
  118.         $shippingAddress->state = isset($delivery_data->state) ? $delivery_data->state : null;
  119.  
  120.         $checkout->request->shipping_address  = $shippingAddress;
  121.  
  122.  
  123.         // Consumer Info
  124.         $consumer  = new \zipMoney\Request\Consumer;
  125.  
  126.         $consumer->first_name = isset($delivery_data->first_name)?$delivery_data->first_name:null;
  127.         $consumer->last_name = isset($delivery_data->last_name)?$delivery_data->last_name:null;
  128.         $consumer->phone = isset($delivery_data->telephone)?$delivery_data->telephone:null;
  129.         $consumer->email = isset($delivery_data->email)?$delivery_data->email:null;
  130.         $consumer->gender = null;
  131.         $consumer->dob = null;
  132.         $consumer->title = "Mr/Mrs";
  133.  
  134.         $checkout->request->consumer  = $consumer;
  135.         $checkout->request->version = new Version();
  136.         $checkout->request->version->platform = "php";
  137.        
  138.  
  139.         try{
  140.             $response = $checkout->process();
  141.  
  142.             /*echo "<pre>";
  143.             print_r($response);
  144.  
  145.             print "\n";
  146.             print "\n";
  147.             print "Please go back and use another payment";
  148.             print "\n";
  149.  
  150.             exit("Status : Declined ! Please try later !");*/
  151.            
  152.  
  153.             if($response->isSuccess())
  154.             {
  155.                 $arr_response = @$response->toArray();
  156.                 $url = @$arr_response['redirect_url'];
  157.  
  158.                 //Do Something
  159.                 header('Location: '.$url);
  160.  
  161.                 exit();
  162.  
  163.                 #$result = 'Payment Success!';
  164.            } else {
  165.                 //Handle Error
  166.                 $result = 'Invalid Request. Please try again !';
  167.             }
  168.  
  169.         } catch (Exception $e){
  170.  
  171.             echo "<pre>";
  172.             print_r($response);
  173.  
  174.  
  175.             // Handle Error
  176.             $result = 'Oops! Something went wrong. Please try again !';
  177.         }
  178.  
  179.         return $result;
  180.  
  181.  
  182.     }
  183.  
  184. }
Advertisement
Add Comment
Please, Sign In to add comment