Thursday, March 21, 2013

PayPal - Express Checkout paypal

Include:
Overview: Paypal have 2 version:
- Real Payment: You will pay real money.
- Sandbox Payment: Help you test some order in paypal.
Step 1: Create form to post data to Paypal
Step 2: Create function Paypal response.

Step 1: Create form to post data to Paypal
This html to you post form

<form action="<?php echo PAYPAL_URL ?>" method="post">
    <!-- <input type="hidden" name="cmd" value="_xclick"> -->
    <input type="hidden" name="cmd" value="_ext-enter">
    <input type="hidden" name="redirect_cmd" value="_xclick">
    <input type="hidden" name="business" value="<?php echo PAYPAL_ACOUNT ?>">
    <input type="hidden" name="item_name" value="<?php echo $this->template['TemplateName'] ?>">
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="notify_url" value="<?php echo BASE_URL.$this->url(array('controller' => 'payment', 'action' => 'notify', 'type' => 'paypal', 'user-id' => Vts_App::getUserLogin()->UserId), null, true) ?>">
    <input type="hidden" name="amount" value="<?php echo $this->amount ?>">
    <input type="hidden" name="return" value="<?php echo BASE_URL. $this->url(array('controller' => 'order', 'action' => 'success', 'type' => 'paypal'), null, true) ?>">
    <input type="hidden" name="cancel_return" value="<?php echo BASE_URL. $this->url(array('controller' => 'template', 'action' => 'detail', 'id' => $this->template['TemplateId']), null, true) ?>">
    <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>

With :
cmd: Is command line send to paypal
redirect_cmd: Paypal will redirect to this url after execute cmd
business: Email of bussiness
item_name: Product name that sale to customer
notify_url: This is url system will auto response when execute. You will update your order when paypal notify to you payment success.

Step 2: Create function Paypal response.
You can access to sandbox of paypal to create document. You will see all parameters in ISP.
After you will update to Order.

Good luck to you.

No comments:

Post a Comment