SHARE
TWEET

Veritrans VT-WEB Notification

mrsnax Aug 18th, 2014 233 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.         Script By MRSNAX :: http://www.sterli.net/
  3.         Twitter @sterli
  4.  
  5.         VT-WEB 3.0
  6.  
  7.         1. First, Since Veritrans won't give right notification each transaction successfully or not. So, I make this code to make all
  8.         developers VT-WEB running handling easy.
  9.  
  10.         2. You MUST setup all redirection to : this-code.php
  11.            e.g.:
  12.  
  13.         --> Payment Notification URL            redirect to     this-code.php
  14.         --> Finish Redirect URL                 redirect to     this-code.php
  15.         --> UnFinish Redirect URL               redirect to     this-code.php
  16.         --> Error Redirect URL                  redirect to     this-code.php
  17.  
  18.         3. Any suggestion please mention by twitter
  19.         4. Thanks.
  20. */
  21.  
  22. require_once("YOUR_VERITRANS_LIBRARIES/Veritrans.php");
  23.  
  24. // Development
  25. #$server_key = "<your-server-key>";
  26.  
  27.  
  28. // TODO : change to production URL for your production Environment
  29. // sandbox/development/testing environment:
  30. $endpoint = "https://api.sandbox.veritrans.co.id/v2/" . $_SESSION["YOUR_ORDER_ID"] . "/status";
  31.  
  32.  
  33. // production environment:
  34. // $endpoint = "https://api.veritrans.co.id/v2/" . $_SESSION["YOUR_ORDER_ID"] . "/status";;
  35.  
  36. $request = curl_init($endpoint);
  37.                 curl_setopt($request, CURLOPT_CUSTOMREQUEST, "GET");
  38.                 curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
  39.                 curl_setopt($request, CURLOPT_SSL_VERIFYPEER, false);
  40.                 $auth = sprintf('Authorization: Basic %s', base64_encode($server_key.':'));
  41.                 curl_setopt($request, CURLOPT_HTTPHEADER, array(
  42.                 'Content-Type: application/json',
  43.                 'Accept: application/json',
  44.                 $auth
  45.         )
  46. );
  47.  
  48. $response = json_decode(curl_exec($request));
  49.  
  50.  
  51. /* UNCOMMENT FOR debug ONLY
  52.         echo "<pre>";
  53.                 print_r($response);
  54.         echo "</pre>";
  55. /* end of debug */
  56.  
  57. // Feedback $response status
  58. if ($response->transaction_status == 'capture') {
  59.         if ($response->fraud_status == 'challenge') {
  60.         // TODO Set payment status in merchant's database to 'challenge'
  61.  
  62.         // NOW redirect to success page
  63.         header("location: your-page-success.html");    
  64.  
  65.         }
  66.         else if ($response->fraud_status == 'accept') {
  67.         // TODO Set payment status in merchant's database to 'success'
  68.  
  69.         // NOW redirect to success page
  70.         header("location: your-page-success.html");    
  71.         }
  72.  
  73. }
  74. else if ($response->transaction_status == 'cancel') {
  75.         if ($response->fraud_status == 'challenge') {
  76.         // TODO Set payment status in merchant's database to 'failure'
  77.  
  78.         // NOW redirect to success page
  79.         header("location: your-page-unsuccess.html");  
  80.        
  81.         }
  82.         else if ($response->fraud_status == 'accept') {
  83.         // TODO Set payment status in merchant's database to 'failure'
  84.  
  85.         // NOW redirect to unsuccess page
  86.         header("location: your-page-unsuccess.html");  
  87.         }
  88.  
  89. }
  90. else if ($response->transaction_status == 'deny') {
  91.  
  92.         // NOW redirect to success page
  93.         header("location: your-page-unsuccess.html");  
  94.  
  95. }
RAW Paste Data
Top