selimppc

zipMoney

Apr 4th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.71 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, $zip_pay_invoice)
  34.     {
  35.  
  36.         /*
  37.         SANDBOX
  38.             Merchant ID: 3075
  39.             API Signature: TRjrjwZSprkucEtpL9BNOZPpkjydDIAk0Rlh7iYYbc0=
  40.             Unique Id: daef00bf-536f-41b2-9bc7-2f1a47fc1742
  41.          */
  42.  
  43.         /*
  44.          *  Merchant ID: 3075
  45.             API Signature: TRjrjwZSprkucEtpL9BNOZPpkjydDIAk0Rlh7iYYbc0=
  46.             Unique Id: daef00bf-536f-41b2-9bc7-2f1a47fc1742
  47.          */
  48.  
  49.  
  50.         zipMoney\Configuration::$merchant_id  = 3075; //sandbox;
  51.         #zipMoney\Configuration::$merchant_id  = 2485; //production;
  52.  
  53.         zipMoney\Configuration::$merchant_key = 'TRjrjwZSprkucEtpL9BNOZPpkjydDIAk0Rlh7iYYbc0='; //sandbox
  54.         #zipMoney\Configuration::$merchant_key = '3t50JGRyQZeg7X3/00emLUvZYVp4BRLq/j8ty3256ec='; // production
  55.  
  56.         zipMoney\Configuration::$environment  = 'sandbox'; //sandbox;
  57.         #zipMoney\Configuration::$environment  = 'production'; //production;
  58.  
  59.  
  60.         # Initialize the checkout
  61.        $checkout = new \zipMoney\Api\Checkout();
  62.  
  63.         $checkout->request->charge = true;
  64.         $checkout->request->currency_code = "AUD";
  65.         $checkout->request->txn_id = false;
  66.         $checkout->request->order_id =  $invoice_number; //$this->_current_order_id;
  67.         $checkout->request->in_store = false;
  68.  
  69.         $checkout->request->cart_url    = "http://staging.asimstoys.com.au/mycart";
  70.         $checkout->request->success_url =
  71. "http://staging.asimstoys.com.au/redirect_e_way_d/".$invoice_number."/".$order_head->net_amount."/".$customer_data->id
  72. ;
  73.         //"{{route('redirect_e_way_d', [$invoice_number, $order_head->net_amount, $customer_data->id])}}";
  74.         $checkout->request->cancel_url  =
  75. "http://staging.asimstoys.com.au/redirect_e_way_d/zip-pay-cancel/".$invoice_number;
  76.         $checkout->request->error_url   =
  77. "http://staging.asimstoys.com.au/redirect_e_way_d/zip-pay-error/".$invoice_number;
  78.         $checkout->request->refer_url   =
  79. "http://staging.asimstoys.com.au/redirect_e_way_d/zip-pay-refer/".$invoice_number;
  80.         $checkout->request->decline_url =
  81. "http://staging.asimstoys.com.au/redirect_e_way_d/zip-pay-decline/".$invoice_number;
  82.  
  83.  
  84. $checkout->request->redirect_url =
  85. "http://staging.asimstoys.com.au/redirect_e_way_d/zip-pay-redirect_url/".$zip_pay_invoice;
  86.  
  87.         // Order Info
  88.         $order = new \zipMoney\Request\Order;
  89.         $order->id = $invoice_number or null;
  90.         $order->tax = 0;
  91.         $order->shipping_tax = 0;
  92.         $order->shipping_value = 0;
  93.         $order->total = $order_head->net_amount + $order->shipping_value;
  94.  
  95.         // Order Item 1
  96.         foreach ($order_detail as  $value)
  97.         {
  98.  
  99.             $order_item = new \zipMoney\Request\OrderItem;
  100.             $product = $customer_data = DB::table('product')->where('id',$value->product_id)->first();
  101.             $order_item->id = $value->product_id;
  102.             $order_item->sku  = $product->slug;
  103.             $order_item->name = $product->title;
  104.             $order_item->price =  $value->price;
  105.             $order_item->quantity = $value->qty;
  106.             $order_item->image_url = 'http://asimstoys.com.au/'.$product->image;
  107.  
  108.             $order->detail[] = $order_item;
  109.         }
  110.  
  111.  
  112.         $checkout->request->order = $order;
  113.  
  114.         // Billing Address
  115.         $billingAddress  = new \zipMoney\Request\Address;
  116.  
  117.  
  118.         $billingAddress->first_name = isset($customer_data->first_name)?$customer_data->first_name : null;
  119.         $billingAddress->last_name = isset($customer_data->first_name)?$customer_data->first_name : null;
  120.         $billingAddress->line1 = isset($customer_data->first_name)?$customer_data->first_name : null;
  121.         $billingAddress->line2 = isset($customer_data->suburb)?$customer_data->suburb : null;
  122.         $billingAddress->country = isset($customer_data->country)?$customer_data->country : null;
  123.         $billingAddress->zip = isset($customer_data->postcode)?$customer_data->postcode : null;
  124.         $billingAddress->city = isset($customer_data->state)?$customer_data->state : null;
  125.         $billingAddress->state = isset($customer_data->state)?$customer_data->state : null;
  126.  
  127.         $checkout->request->billing_address  = $billingAddress;
  128.  
  129.         // Shipping Address
  130.         $shippingAddress = new \zipMoney\Request\Address;
  131.  
  132.         $shippingAddress->first_name = isset($delivery_data->first_name)?$delivery_data->first_name : null;
  133.         $shippingAddress->last_name = isset($delivery_data->first_name)?$delivery_data->first_name:null;
  134.         $shippingAddress->line1 = isset($delivery_data->first_name)? $delivery_data->first_name : null;
  135.         $shippingAddress->line2 = isset($delivery_data->suburb)?$delivery_data->suburb : null;
  136.         $shippingAddress->country = isset($delivery_data->country ) ? $delivery_data->country : null;
  137.         $shippingAddress->zip = isset($delivery_data->postcode) ?$delivery_data->postcode : null;
  138.         $shippingAddress->city = isset($delivery_data->state) ?$delivery_data->state : null;
  139.         $shippingAddress->state = isset($delivery_data->state) ? $delivery_data->state : null;
  140.  
  141.         $checkout->request->shipping_address  = $shippingAddress;
  142.  
  143.  
  144.         // Consumer Info
  145.         $consumer  = new \zipMoney\Request\Consumer;
  146.  
  147.         $consumer->first_name = isset($delivery_data->first_name)?$delivery_data->first_name:null;
  148.         $consumer->last_name = isset($delivery_data->last_name)?$delivery_data->last_name:null;
  149.         $consumer->phone = isset($delivery_data->telephone)?$delivery_data->telephone:null;
  150.         $consumer->email = isset($delivery_data->email)?$delivery_data->email:null;
  151.         $consumer->gender = null;
  152.         $consumer->dob = null;
  153.         $consumer->title = "Mr/Mrs";
  154.  
  155.         $checkout->request->consumer  = $consumer;
  156.         $checkout->request->version = new Version();
  157.         $checkout->request->version->platform = "php";
  158.        
  159.  
  160.         try{
  161.             $response = $checkout->process();
  162.  
  163.             /*echo "<pre>";
  164.             print_r($response);
  165.  
  166.             print "\n";
  167.             print "\n";
  168.             print "Please go back and use another payment";
  169.             print "\n";
  170.  
  171.             exit("Status : Declined ! Please try later !");*/
  172.            
  173.  
  174.             if($response->isSuccess())
  175.             {
  176.                 $arr_response = @$response->toArray();
  177.                 $url = @$arr_response['redirect_url'];
  178.  
  179.                 //Do Something
  180.                 header('Location: '.$url);
  181.  
  182.                 exit();
  183.  
  184.                 #$result = 'Payment Success!';
  185.            } else {
  186.                 //Handle Error
  187.                 $result = 'Invalid Request. Please try again !';
  188.             }
  189.  
  190.         } catch (Exception $e){
  191.  
  192.             echo "<pre>";
  193.             print_r($response);
  194.  
  195.             print "\n";
  196.             print "\n";
  197.             print "Please go back and use another payment";
  198.             print "\n";
  199.  
  200.             exit("Status : Declined ! Please try later !");
  201.  
  202.             // Handle Error
  203.             $result = 'Oops! Something went wrong. Please try again !';
  204.         }
  205.  
  206.         return $result;
  207.  
  208.  
  209.     }
  210.  
  211. }
Add Comment
Please, Sign In to add comment