Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Script By MRSNAX :: http://www.sterli.net/
- Twitter @sterli
- VT-WEB 3.0
- 1. First, Since Veritrans won't give right notification each transaction successfully or not. So, I make this code to make all
- developers VT-WEB running handling easy.
- 2. You MUST setup all redirection to : this-code.php
- e.g.:
- --> Payment Notification URL redirect to this-code.php
- --> Finish Redirect URL redirect to this-code.php
- --> UnFinish Redirect URL redirect to this-code.php
- --> Error Redirect URL redirect to this-code.php
- 3. Any suggestion please mention by twitter
- 4. Thanks.
- */
- require_once("YOUR_VERITRANS_LIBRARIES/Veritrans.php");
- // Development
- #$server_key = "<your-server-key>";
- // TODO : change to production URL for your production Environment
- // sandbox/development/testing environment:
- $endpoint = "https://api.sandbox.veritrans.co.id/v2/" . $_SESSION["YOUR_ORDER_ID"] . "/status";
- // production environment:
- // $endpoint = "https://api.veritrans.co.id/v2/" . $_SESSION["YOUR_ORDER_ID"] . "/status";;
- $request = curl_init($endpoint);
- curl_setopt($request, CURLOPT_CUSTOMREQUEST, "GET");
- curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($request, CURLOPT_SSL_VERIFYPEER, false);
- $auth = sprintf('Authorization: Basic %s', base64_encode($server_key.':'));
- curl_setopt($request, CURLOPT_HTTPHEADER, array(
- 'Content-Type: application/json',
- 'Accept: application/json',
- $auth
- )
- );
- $response = json_decode(curl_exec($request));
- /* UNCOMMENT FOR debug ONLY
- echo "<pre>";
- print_r($response);
- echo "</pre>";
- /* end of debug */
- // Feedback $response status
- if ($response->transaction_status == 'capture') {
- if ($response->fraud_status == 'challenge') {
- // TODO Set payment status in merchant's database to 'challenge'
- // NOW redirect to success page
- header("location: your-page-success.html");
- }
- else if ($response->fraud_status == 'accept') {
- // TODO Set payment status in merchant's database to 'success'
- // NOW redirect to success page
- header("location: your-page-success.html");
- }
- }
- else if ($response->transaction_status == 'cancel') {
- if ($response->fraud_status == 'challenge') {
- // TODO Set payment status in merchant's database to 'failure'
- // NOW redirect to success page
- header("location: your-page-unsuccess.html");
- }
- else if ($response->fraud_status == 'accept') {
- // TODO Set payment status in merchant's database to 'failure'
- // NOW redirect to unsuccess page
- header("location: your-page-unsuccess.html");
- }
- }
- else if ($response->transaction_status == 'deny') {
- // NOW redirect to success page
- header("location: your-page-unsuccess.html");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement