开发者

Need help with Zend form to Paypal site

I created a Zend form (the user can specify the payment details and amount of money they wanted to deposit into my back end system) when they submitted the details it go through to the validation function to ensure all the data is validated. But after validation I wanted to submit the necessary payment dat开发者_高级运维a to paypal IPN website and forward the user to paypal website as well (so they can enter their paypal email and password for transaction).

But I have no clue how can I achieve this? Do I need to create a new Zend Form object and post the data to paypal website or there is a easy way to submit the data to paypal and forward the user to the paypal website? If possible can u show me how I can code this?

Thanks so much in advance.


Assuming you use Express Checkout, the easiest way to do this is to simply redirect user to another page saying "redirecting to paypal..." after your validation.

At that page you'll have a hidden form (you can construct it with Zend_Form or manuallly, it does not really matter), you can then add some javascript to submit that form and also leave "submit" button visible so that user could click it if tired waiting until javascript does it for him.

Or this can simply be a "thank you" page, e.g.:

Thank you for your order! Your order number is 27335

[Click here] to complete the payment.

After they payment is done, paypal will return to your IPN URL which you specified. You can then check it like this:

$paypal_url = 'https://www.paypal.com/cgi-bin/webscr';
$client = new Zend_Http_Client($paypal_url);
$client->setMethod(Zend_Http_Client::POST);
$client->setParameterPost(array('cmd' => '_notify-validate')+$_POST);
$response = $client->request();

if ($response->getBody() !== 'VERIFIED') {
    //Not verified
    die("FAIL");
}

This peace of code simply ensures that what you got from IPN really comes from paypal. After that, you will also need to check the params it has passed to you in $_POST (like order number, amount, currency etc). You will also need item_number to "link" it with the order# you should have added before redirecting to PayPal.

You can also check other ways doing checkout, which PayPal suggests here https://cms.paypal.com/ca/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_WPGettingStarted

Alternatively, you can also try PayPal NVP solution.


Here's a Zend Framework Paypal NVP tutorial right off of my blog if you need to know: http://www.alexventure.com/2011/02/28/zend-framework-and-the-paypal-api-part-1-of-2/

It covers implementation of PayPal Website Payments Pro during the first part, and PayPal Express Checkout during the second part. It's done using the PayPal NVP API and the Zend Framework Zend_Http_Client class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜