https://github.com/ankitsardhara/peachpayment
config.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?php function developmentMode(){ return 'dev'; //return 'prod'; } function paymentURL(){ return 'https://test.oppwa.com'; //development; //return 'https://oppwa.com/'; // production; } function entityId(){ // Dashboard -> Merchants -> click on merchant -> Development -> API Credentials return '***7a4c873384a2a01734ca9dac93535';//(Sender) } function accessToken(){ // Dashboard -> Merchants -> click on merchant -> Development -> API Credentials return '***jN2E0Yzk3MzM4MTM3OTAxNzM0Y2E4YzU5YjJlMWR8a0FzdEJyY1M4UA==';//(Access Token) } |
index.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
<?php require 'config.php'; $paymentURL=paymentURL(); $entityId=entityId(); $accessToken=accessToken(); $developmentMode=developmentMode(); $url = $paymentURL."/v1/checkouts"; $data = "entityId=".$entityId. "&amount=92.00" . "¤cy=ZAR" . "&paymentType=DB"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization:Bearer '.$accessToken)); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); if($developmentMode=='dev'){ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);// this should be set to true in production }else{ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);// this should be set to true in production } curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $responseData = curl_exec($ch); if(curl_errno($ch)) { echo curl_error($ch); die; } curl_close($ch); $responseData=json_decode($responseData,true); if(!isset($responseData['id'])){ echo "something went wrong"; die; } $checkout_id=$responseData['id']; ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <div style="width: 200px; margin: 0 auto;"> <h5>Card Number: 5454545454545454</h5> <h5>Expiry Date: 01/30</h5> <h5>Card holder: Ankit</h5> <h5>CVV : 12</h5> </div> <form action="http://localhost/peachpayment/pay.php?user_id=1" class="paymentWidgets" data-brands="VISA MASTER AMEX"> </form> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script type="text/javascript"> var JSLink = "<?php echo $paymentURL; ?>/v1/paymentWidgets.js?checkoutId=<?php echo $checkout_id; ?>"; var JSElement = document.createElement('script'); JSElement.src = JSLink; //JSElement.onload = OnceLoaded; document.getElementsByTagName('head')[0].appendChild(JSElement); </script> </body> </html> |
pay.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
<?php require 'config.php'; $paymentURL=paymentURL(); $entityId=entityId(); $accessToken=accessToken(); $developmentMode=developmentMode(); $url = $paymentURL."/v1/checkouts"; $params=$_REQUEST; $url = $paymentURL."".$params['resourcePath']."?entityId=".$entityId;; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization:Bearer '.$accessToken)); if($developmentMode=='dev'){ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);// this should be set to true in production }else{ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);// this should be set to true in production } curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $responseData = curl_exec($ch); if(curl_errno($ch)) { $res= curl_error($ch); } curl_close($ch); $responseData=json_decode($responseData,true); echo "<pre>"; print_r($responseData); |
More Stories
Mollie Payment – PHP Laravel
Difference between file, file_get_contents, and fopen in PHP
Clear cache in laravel