Safe determination of dynamic amounts using Paypal payments with redirection, not a button?

Well, I haven’t worked with hosted buttons before, but that makes sense as they are much more secure.

I looked around and read the documents (which are not all so useful), and the best help I have found so far is here ; although I'm still confused by where exactly to put this code?

Also, I technically don't want a “button”, but the idea behind them seems to be what I want.

All I want to do is use the same query windows every time, but I just want to change the price - the price is dynamic depending on what the user selects on the form.

In addition, I do not need a button by itself, I would prefer to redirect the user to paypal with the corresponding data, but not sure how to do this when setting a dynamic price?

If I don’t need to set a dynamic price, I know that I could just add the request URL for the hosted button to the URL, and then redirect to that URL, but I need to change the price and therefore my question. ..

+5
source share
3 answers

Well, finally it turned out that the response of the BMUpdateButton API returns HTML to create the form, and also returns other data also in the returned array.

Once you make a request, it will return an array with three keys according to the BMUpdateButton Response section of the API page linked above.

It:

  • WEBSITECODE

    HTML for web pages

    • EMAILLINK

This is what I was looking for; simple link that you can redirect users to

  • HOSTEDBUTTONID

Button ID

When changing the contents of a hosted button, you need to transfer all the details of the button, as when creating it; so, for example, if you do not pass the item name to it, the item name will be blank and Paypal will allow the user to set it.

In addition, the important note is that when updating the button information, it is not just updated for this user session, it updates it in your PayPal account, so the new name / price, etc. will affect all users who try to use it.

If you still want to update the button information, you can do this with the help of below:

I personally started with this class:

 <?php class Paypal { /** * Last error message(s) * @var array */ protected $_errors = array(); /** * API Credentials * Use the correct credentials for the environment in use (Live / Sandbox) * @var array */ protected $_credentials = array( 'USER' => 'seller_1297608781_biz_api1.lionite.com', 'PWD' => '1297608792', 'SIGNATURE' => 'A3g66.FS3NAf4mkHn3BDQdpo6JD.ACcPc4wMrInvUEqO3Uapovity47p', ); /** * API endpoint * Live - https://api-3t.paypal.com/nvp * Sandbox - https://api-3t.sandbox.paypal.com/nvp * @var string */ protected $_endPoint = 'https://api-3t.sandbox.paypal.com/nvp'; /** * API Version * @var string */ protected $_version = '74.0'; /** * Make API request * * @param string $method string API method to request * @param array $params Additional request parameters * @return array / boolean Response array / boolean false on failure */ public function request($method, $params = array()) { $this->_errors = array(); if (empty($method)) { //Check if API method is not empty $this->_errors = array('API method is missing'); return false; } //Our request parameters $requestParams = array( 'METHOD' => $method, 'VERSION' => $this->_version ) + $this->_credentials; //Building our NVP string $request = http_build_query($requestParams + $params); //cURL settings $curlOptions = array( CURLOPT_URL => $this->_endPoint, CURLOPT_VERBOSE => 1, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_CAINFO => dirname(__FILE__) . '/cacert.pem', //CA cert file CURLOPT_RETURNTRANSFER => 1, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $request ); $ch = curl_init(); curl_setopt_array($ch, $curlOptions); //Sending our request - $response will hold the API response $response = curl_exec($ch); //Checking for cURL errors if (curl_errno($ch)) { $this->_errors = curl_error($ch); curl_close($ch); return false; //Handle errors } else { curl_close($ch); $responseArray = array(); parse_str($response, $responseArray); // Break the NVP string to an array return $responseArray; } } } ?> 

Credit: https://www.smashingmagazine.com/2011/09/getting-started-with-the-paypal-api/

Then I did the following:

 include(dirname(__FILE__) . '/includes/paypal.class.php'); $paypal = new Paypal(); // Set our method $method = 'BMUpdateButton'; // Set our params $params = array( 'HOSTEDBUTTONID' => 'your_button_id', 'BUTTONTYPE' => 'BUYNOW', 'BUTTONSUBTYPE' => 'SERVICES', 'L_BUTTONVAR0' => 'item_name=Your Description', 'L_BUTTONVAR1' => 'amount=999.00', 'L_BUTTONVAR2' => 'currency_code=AUD', 'L_BUTTONVAR3' => 'cancel_return=http://www.example.com/cancel.html', 'L_BUTTONVAR4' => 'return=http://www.example.com/success.html' ); // Make request to change button details $result = $paypal->request($method, $params); 

Please note that although Paypal says BUTTONSUBTYPE is optional, you will most likely receive an error message if you do not enable it.

+2
source

You need to use your button designer if you are going to make placed buttons.

https://www.paypal.com/us/cgi-bin/webscr?cmd=_button-designer

Security occurs after checking the IPN after the transaction.

Cm:

https://www.paypal.com/us/cgi-bin/webscr?cmd=p/acc/ipn-info-outside

Confirm that an IPN call from PayPal?

The answer to this post is the best way to do this:

Dynamically creating a PayPal button - isn't it very uncertain?

0
source

Button code is HTML form tags, so you can easily convert them to a string request and collect your dynamic useful data in this format:

 https://www.paypal.com/cgi-bin/webscr?cmd=_xclick& business=yourAccount@email.com &item_name=itemNameTest&item_number=123&amount=1&currency_code=USD&no_shipping=1 

Set it up and add the vars to the varliables below HERE and use it with your redirection method.

The button manager API is more comprehensive, except that it will not return you the URL of the query string like this, although the idea behind is identical to the HTML code snippet

0
source

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


All Articles