My client has a website selling some electronic consumables (e.g. batteries), there are currently under 20 products and for each product, he has created some hosted buttons in his PayPal account and copied the html and pasted in that product's page, like this:
Buy 1 for $5 [Buy]
Buy 5 for $23 [Buy] Buy 10 for $45 [Buy]Now, he wants to allow the customers to enter the number of items to buy, and would like the system to calculate price for him/her taking the discount into consideration.
For example, a customer enters 17, it then shows the price he/she needs to 开发者_如何学Cpay,
Buy [17] for $45+$23+($5x2)=$78 [Buy]I can use javascript to do this calculation and display it in the product page, but I need to make it interact with PayPal correctly.
I have googled and I think I need to make use of the Button Manager API, Encrypted buttons and Clear text buttons are possibly what I need.
But which one is better for this situation? The implementation should be as simple as possible.
Please kindly advise.
Thanks in advance.
The simplest solution is to generate your own payment URLs and link a buy graphic/form to that URL, rather than use a PayPal button.
https://www.paypal.com/cgi-bin/webscr?
cmd=_ext-enter
&redirect_cmd=_xclick
&business=YOUR_EMAIL
&item_name=ITEM_NAME
&item_number=ITEM_NUMBER
¤cy_code=USD
&amount=12345.67
&shipping=0
&tax=0
&return=RETURN_URL
&cancel_return=CANCEL_URL
¬ify_url=IPN_URL
Just replace the values as needed. You'll want to write an IPN script to take the notification postbacks and update his order database as each payment comes in, which is also where you verify the link wasn't tampered with by the user (if the payment amount doesn't match the amount the products should be for, etc).
I've implemented PayPal interactions a few different ways, and the best balance I've found between feature-filled and still relatively easy to implement is the Name-Value Pair (NVP) API. Parameters are sent to PayPal servers using an HTTP request populated with the necessary parameters. An overview of the NVP API is available here.
An application using this API needs to send 3 messages to PayPal:
- SetExpressCheckout to initiate the user's checkout
- GetExpressCheckoutDetails to get the payer's ID from PayPal necessary to complete the payment
- DoExpressCheckoutPayment to complete the transaction
精彩评论