Programming at PayPal

First of all, I own PHP :)

But I'm noob at Paypal :) So ... How can I make separate buttons for buying buttons? Something like this: I created a CMS to add new items for sale. But every time I add an item, I have to go to Paypal to create this item so that it can be bought ... Is there a way to do this automatically? Thus, when I add a new item, I can just buy it ... Is there a Paypal solution for this? Something in the API?

Thanks!

+4
source share
1 answer

If you have a merchant account, you can use the Paypal NVP API to fully process payments from the server. I have developed several such systems. The documentation is fine, but there are some great places where you might just get lost.

This is a sample from one of my payment object methods, it uses the paypal API and returns a response code:

// this line gets a query string out of the posted payment data $details = $this->___prepare_for_paypal($details); if (!$details) return false; $API_USERNAME = 'USERNAMEHERE'; $API_PASSWORD = 'PASSWORDHERE'; $API_CERTIFICATE = '/usr/web/paypal/cert_key_pem'; $API_SIGNATURE = ''; $API_ENDPOINT = 'https://api.paypal.com/nvp'; $PAYPAL_URL = 'https://www.paypal.com/webscr&cmd=_express-checkout&token='; $VERSION = '51.0'; //setting the curl parameters. $ch = curl_init(); curl_setopt($ch, CURLOPT_SSLCERT, $API_CERTIFICATE); curl_setopt($ch, CURLOPT_URL,$API_ENDPOINT); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_POST, 1); //NVPRequest for submitting to server $nvpreq="METHOD=doDirectPayment&VERSION=".urlencode($VERSION)."&PWD=".urlencode($API_PASSWORD)."&USER=".urlencode($API_USERNAME).$details; //setting the nvpreq as POST FIELD to curl curl_setopt($ch,CURLOPT_POSTFIELDS,$nvpreq); //getting response from server $response = curl_exec($ch); //convrting NVPResponse to an Associative Array $nvpResArray=$this->___deformat_NVP($response); // check the API response array. ACK will contain the word 'Success' if everything went through ok $ack = strtoupper($nvpResArray["ACK"]); // if we get no love from paypal, stick the transaction into the DB for reference if($ack=="FAILURE") { $err_details = addslashes(serialize($nvpResArray)); $err_details .= '||||'.addslashes($nvpreq); $sql = 'INSERT INTO payment_errors (time, user_id, details) VALUES ('.time().','.(user::export()->id ? user::export()->id : '0').',"'.$err_details.'")'; db::update($sql); if (isset($nvpResArray['L_LONGMESSAGE0'])) $this->_data['error_message'] = $nvpResArray['L_LONGMESSAGE0']; if (isset($nvpResArray['L_LONGMESSAGE0'])) $this->_data['error_code'] = $nvpResArray['L_ERRORCODE0']; return false; } return $nvpResArray['TRANSACTIONID']; 
+3
source

Source: https://habr.com/ru/post/1339748/


All Articles