diff --git a/docs/ExpressCheckout.md b/docs/ExpressCheckout.md index ee1feb6..969bb00 100644 --- a/docs/ExpressCheckout.md +++ b/docs/ExpressCheckout.md @@ -1,32 +1,83 @@ +PayPal Express Checkout provides a very easy and user friendly way for users to make payment. All transactions happen in an overlayer modal box or popup window (it mostly depends on the user choice of "Remember Me Cookie"). It seems like users don't need to leave your site during the whole process unlike other methods, where users will be redirected to the 'full' PayPal official site to make payment. + ExpressCheckout does not use any other configurations than those for authentication. -The order has three required fields: - - `total_price` - - `items_price` - - `shipping_price` +The order is an array of items with three required fields: + - `name` + - `price` + - `quantity` **Example**: -``` php +```php +$items = array(); +$items[] = array('name' => 'Item Name #1', 'price' => 3, 'quantity' => 1); +$items[] = array('name' => 'Item Name #2', 'price' => 5, 'quantity' => 3); + $express_checkout = Payment::instance('ExpressCheckout') - ->order(array( - 'items_price' => 50, - 'shipping_price' => 10, - 'total_price' => 60 - )) + ->order($items) ->return_url('example.com/success') - ->cancel_url('example.com/cancelled') - ->notify_url('example.com/ipn'); + ->cancel_url('example.com/cancelled'); $response = $express_checkout ->set_express_checkout(); - -// Redirecting the user to confirm the payment using $response['TOKEN'] +``` -$express_checkout - ->do_express_checkout_payment($response['TOKEN'], $response['PAYERID']); +Now when you have ```$response['TOKEN']``` you need to open a popup with Paypal page. You can get valid URL for the form action by ```$express_checkout->ec_form_action_url($response['TOKEN'])```: +```html +
+``` +Upon success Paypal redirects to your ```return_url``` where you need to finally complete the payment and act accordingly: +```php +$params['TOKEN'] = $_REQUEST['token']; +$params['PAYERID'] = $_REQUEST['PayerID']; + +$express_checkout = Payment::instance('ExpressCheckout') + ->order($items); //the same $items as before + +//In $response you'd have some extra important information like transaction id or fees taken by Paypal +$response = $express_checkout + ->do_express_checkout_payment($params['TOKEN'], $params['PAYERID']); + +$ack = strtoupper($response["ACK"]); +if("SUCCESS" == $ack || "SUCCESSWITHWARNING" == $ack) +{ + /* + * TODO: Proceed with desired action after the payment + * (ex: start download, start streaming, add coins to the game, etc.) + */ +} ``` **Notes**: -You should store the token or the whole response in a permanent or a session storage. They will be needed after the user has confirmed the payment on paypal.com. + - You should store the token or the whole response in a permanent or a session storage. They will be needed after the user has confirmed the payment on paypal.com. + + - You also need to have this code before ```