selimppc

Zip-pay Library in PHP

Nov 4th, 2016
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.17 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.  
  19. #use Faker\Provider\DateTime;
  20.  
  21. class ZipPay
  22. {
  23.     /**
  24.      * @param $invoice_number
  25.      * @param $order_head
  26.      * @param $order_detail
  27.      * @param $customer_data
  28.      * @param $delivery_data
  29.      * @throws zipMoney\Exception
  30.      */
  31.     public static function call_to_server($invoice_number, $order_head, $order_detail, $customer_data, $delivery_data)
  32.     {
  33.  
  34.  
  35.         /*
  36.         SANDBOX
  37.             Merchant ID: 3075
  38.             API Signature: TRjrjwZSprkucEtpL9BNOZPpkjydDIAk0Rlh7iYYbc0=
  39.             Unique Id: daef00bf-536f-41b2-9bc7-2f1a47fc1742
  40.          */
  41.  
  42.         /*
  43.          *  Merchant ID: 3075
  44.             API Signature: TRjrjwZSprkucEtpL9BNOZPpkjydDIAk0Rlh7iYYbc0=
  45.             Unique Id: daef00bf-536f-41b2-9bc7-2f1a47fc1742
  46.          */
  47.  
  48.         zipMoney\Configuration::$merchant_id  = 3075;
  49.         zipMoney\Configuration::$merchant_key = 'TRjrjwZSprkucEtpL9BNOZPpkjydDIAk0Rlh7iYYbc0=';
  50.         zipMoney\Configuration::$environment  = 'production'; //sandbox|production;
  51.  
  52.  
  53.         # Initialize the checkout
  54.        $checkout = new \zipMoney\Api\Checkout();
  55.  
  56.         $checkout->request->charge = false;
  57.         $checkout->request->currency_code = "AUD";
  58.         $checkout->request->txn_id = false;
  59.         $checkout->request->order_id =  $invoice_number; //$this->_current_order_id;
  60.         $checkout->request->in_store = false;
  61.  
  62.         #$checkout->request->cart_url    = "https://your-domain/checkout/cart/";
  63.        $checkout->request->success_url = "{{route('redirect_e_way_d', [$invoice_number, $order_head->net_amount, $customer_data->id])}}";
  64.         #$checkout->request->cancel_url  = "https://your-domain/zipmoney/express/cancel/";
  65.        #$checkout->request->error_url   = "https://your-domain/zipmoney/express/error/";
  66.        #$checkout->request->refer_url   = "https://your-domain/zipmoney/express/refer/";
  67.        #$checkout->request->decline_url = "https://your-domain/zipmoney/express/decline/";
  68.  
  69.         // Order Info
  70.         $order = new \zipMoney\Request\Order;
  71.         $order->id = $invoice_number or null;
  72.         $order->tax = 0;
  73.         $order->shipping_tax = 0;
  74.         $order->shipping_value = 1;
  75.         $order->total = $order_head->net_amount;
  76.  
  77.         // Order Item 1
  78.         foreach ($order_detail as  $value)
  79.         {
  80.  
  81.             $order_item = new \zipMoney\Request\OrderItem;
  82.             $order_item->id = $value->product_id;
  83.             $order_item->sku  = $value->product_id;
  84.             $order_item->name = $value->product_id;
  85.             $order_item->price =  $value->price;
  86.             $order_item->quantity = $value->qty;
  87.  
  88.             $order->detail[] = $order_item;
  89.         }
  90.  
  91.  
  92.         $checkout->request->order = $order;
  93.  
  94.         // Billing Address
  95.         $billingAddress  = new \zipMoney\Request\Address;
  96.  
  97.         $billingAddress->first_name = $customer_data->first_name;
  98.         $billingAddress->last_name = $customer_data->last_name;
  99.         $billingAddress->line1 = $customer_data->suburb;
  100.         $billingAddress->line2 = $customer_data->suburb;
  101.         $billingAddress->country = $customer_data->country;
  102.         $billingAddress->zip = $customer_data->postcode;
  103.         $billingAddress->city = $customer_data->state;
  104.         $billingAddress->state = $customer_data->state;
  105.  
  106.         $checkout->request->billing_address  = $billingAddress;
  107.  
  108.         // Shipping Address
  109.         $shippingAddress = new \zipMoney\Request\Address;
  110.  
  111.         $shippingAddress->first_name = "firstname";
  112.         $shippingAddress->last_name = "lastname";
  113.         $shippingAddress->line1 = "line1";
  114.         $shippingAddress->line2 = "line2";
  115.         $shippingAddress->country = "Australia";
  116.         $shippingAddress->zip = "postcode";
  117.         $shippingAddress->city = "Sydney";
  118.         $shippingAddress->state = "NSW";
  119.  
  120.         $checkout->request->shipping_address  = $shippingAddress;
  121.  
  122.  
  123.         // Consumer Info
  124.         $consumer  = new \zipMoney\Request\Consumer;
  125.  
  126.         $consumer->first_name = $delivery_data->first_name;
  127.         $consumer->last_name = $delivery_data->last_name;
  128.         $consumer->phone = $delivery_data->telephone;
  129.         $consumer->email = $delivery_data->email;
  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.             if($response->isSuccess()){
  143.                 //Do Something
  144.                 $result = 'Payment Success!';
  145.             } else {
  146.                 //Handle Error
  147.                 $result = 'Invalid Request. Please try again !';
  148.             }
  149.  
  150.         } catch (Exception $e){
  151.             // Handle Error
  152.             $result = 'Oops! Something went wrong. Please try again !';
  153.         }
  154.  
  155.         return $result;
  156.  
  157.  
  158.     }
  159.  
  160. }
Advertisement
Add Comment
Please, Sign In to add comment