-
Learn 4 Easy Steps to Integrate Standard PayPal Gateway in PHP
over 7 years ago
-
over 7 years ago
Hello @jozospisiak@gmail.com
For verify paypal payment you have to send transaction id to paypal with below code :
<?php //for verify payment by paypall $ch = curl_init(); $clientId = "AYnfAxcwUmqMWMuiZeXDa96asNKmarUEDhS4jRL3bzVGLTl4P20PEzBArmdge6JclwH2_W66UFilvW9P"; //Clinet id of merchant accont $secret = "EB5hxlMM9643evfWHImKgS0CpZRv-n0HjFf1xDSYhnd0bApaxfwT-GRPjsBvEy0uwr4dexX5Fd8Q3_CU";//Secret key of merchant accont curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token"); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSLVERSION , 6); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERPWD, $clientId.":".$secret); curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials"); $result = curl_exec($ch); if(empty($result)){ die("Error: No response."); }else{ //This is the data to be sent in the call $postdata = array( 'USER' => 'merchant.sujit_api1.gmail.com', //write here merchant email 'PWD' => 'AXT8J3ET38DVXA7D', // write here password 'SIGNATURE' => 'AFcWxV21C7fd0v3bYYYRCpSSRl31AxAM8YJrWrtM.D-CmZicgGLTLt0K', // write here signature 'METHOD' => 'GetTransactionDetails', 'VERSION' => '123', 'TransactionID' => $transaction_id // write transaction id here ); $postdata = http_build_query($postdata); $json = json_decode($result); curl_close($ch); $url = 'https://api-3t.sandbox.paypal.com/nvp'; $curl = curl_init($url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($curl, CURLOPT_SSLVERSION , 6); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'Authorization: Bearer '.$json->access_token, 'Accept: application/json', 'Content-Type: application/json' )); curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); $response = curl_exec( $curl ); $verify_tx = urldecode($response); parse_str($verify_tx,$paypal_detail); print_r($paypal_detail); die; } ?>
After executing above code you will get a responce of all details of payment and now you can save all necessary details in database.
Note :- Also check in database with transaction id if this transaction id already exist or not. -
-
over 7 years ago
You are supposed to expose an endpoint for paypal to call, then in that action do a callback to paypal with the response ID to authenticate the call. -
-
over 7 years ago
How do I verify, that the payment was OK? Shouldn't there be some kind of security hash?
Otherwise anyone can just visit the return value with random parameters and therefore confirm their purchase. -
3 Comment(s)