Mardydu

Untitled

Dec 3rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.40 KB | None | 0 0
  1. <?php
  2. require_once(dirname(__FILE__) . '../Veritrans.php');
  3. //Set Your server key
  4. Veritrans_Config::$serverKey = "Mid-server-vsVQ-mQU7vgOdIs7o3_pFCjK";
  5. // Uncomment for production environment
  6. Veritrans_Config::$isProduction = true;
  7. // Enable sanitization
  8. Veritrans_Config::$isSanitized = true;
  9. // Enable 3D-Secure
  10. Veritrans_Config::$is3ds = true;
  11. // Required
  12. $transaction_details = array(
  13.   'order_id' => rand(),
  14.   'gross_amount' => 94000, // no decimal allowed for creditcard
  15. );
  16. // Optional
  17. $item1_details = array(
  18.   'id' => 'a1',
  19.   'price' => 18000,
  20.   'quantity' => 3,
  21.   'name' => "Apple"
  22. );
  23. // Optional
  24. $item2_details = array(
  25.   'id' => 'a2',
  26.   'price' => 20000,
  27.   'quantity' => 2,
  28.   'name' => "Orange"
  29. );
  30. // Optional
  31. $item_details = array ($item1_details, $item2_details);
  32. // Optional
  33. $billing_address = array(
  34.   'first_name'    => "Andri",
  35.   'last_name'     => "Litani",
  36.   'address'       => "Mangga 20",
  37.   'city'          => "Jakarta",
  38.   'postal_code'   => "16602",
  39.   'phone'         => "081122334455",
  40.   'country_code'  => 'IDN'
  41. );
  42. // Optional
  43. $shipping_address = array(
  44.   'first_name'    => "Obet",
  45.   'last_name'     => "Supriadi",
  46.   'address'       => "Manggis 90",
  47.   'city'          => "Jakarta",
  48.   'postal_code'   => "16601",
  49.   'phone'         => "08113366345",
  50.   'country_code'  => 'IDN'
  51. );
  52. // Optional
  53. $customer_details = array(
  54.   'first_name'    => "Andri",
  55.   'last_name'     => "Litani",
  56.   'email'         => "[email protected]",
  57.   'phone'         => "081122334455",
  58.   'billing_address'  => $billing_address,
  59.   'shipping_address' => $shipping_address
  60. );
  61. // Optional, remove this to display all available payment methods
  62. $enable_payments = array('credit_card','cimb_clicks','mandiri_clickpay','echannel');
  63. // Fill transaction details
  64. $transaction = array(
  65.   'enabled_payments' => $enable_payments,
  66.   'transaction_details' => $transaction_details,
  67.   'customer_details' => $customer_details,
  68.   'item_details' => $item_details,
  69. );
  70. $snapToken = Veritrans_Snap::getSnapToken($transaction);
  71. echo "snapToken = ".$snapToken;
  72. ?>
  73.  
  74. <!DOCTYPE html>
  75. <html>
  76.   <body>
  77.     <button id="pay-button">Pay!</button>
  78.     <pre><div id="result-json">JSON result will appear here after payment:<br></div></pre>
  79.  
  80. <!-- TODO: Remove ".sandbox" from script src URL for production environment. Also input your client key in "data-client-key" -->
  81.     <script src="https://app.sandbox.midtrans.com/snap/snap.js" data-client-key="Mid-server-vsVQ-mQU7vgOdIs7o3_pFCjK"></script>
  82.     <script type="text/javascript">
  83.       document.getElementById('pay-button').onclick = function(){
  84.         // SnapToken acquired from previous step
  85.         snap.pay('<?=$snapToken?>', {
  86.           // Optional
  87.           onSuccess: function(result){
  88.             /* You may add your own js here, this is just example */ document.getElementById('result-json').innerHTML += JSON.stringify(result, null, 2);
  89.           },
  90.           // Optional
  91.           onPending: function(result){
  92.             /* You may add your own js here, this is just example */ document.getElementById('result-json').innerHTML += JSON.stringify(result, null, 2);
  93.           },
  94.           // Optional
  95.           onError: function(result){
  96.             /* You may add your own js here, this is just example */ document.getElementById('result-json').innerHTML += JSON.stringify(result, null, 2);
  97.           }
  98.         });
  99.       };
  100.     </script>
  101.   </body>
  102. </html>
Add Comment
Please, Sign In to add comment