Tuesday, October 27, 2009

Paypal Integration

The Basics:

- After shopping all the required items and filling up the checkout form when the "Order" button is clicked, the customer is taken to the paypal website wherein the customer is prompted for either payment through paypal account or through credit card (if not having a paypal account).

- Now during this redirection from checkout page to paypal website, we need to collect/prefill some values that are required on the paypal website. And these values has to be collected/filled in certain pre-defined "html hidden form variables" termed as "paypal form variables". So we have to put an intermediary page between checkout page and the paypal page where these values can be collected.

- The following is the list of paypal form variables:

<form name="order" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">

* <input type="hidden" name="cmd" value="_ext-enter">

* <input type="hidden" name="redirect_cmd" value="_xclick">

* <input type="hidden" name="business" value="testgods@gods.com">

<input type="hidden" name="no_note" value="1">

<input type="hidden" name="no_shipping" value="0">

<input type="hidden" name="first_name" value="FirstName">

<input type="hidden" name="last_name" value="LastName">

<input type="hidden" name="address1" value="Address1">

<input type="hidden" name="address2" value="Address2">

<input type="hidden" name="city" value="City">

<input type="hidden" name="zip" value="PostCode">

<input type="hidden" name="country" value="Country">

<input type="hidden" name="email" value="Email">

* <input type="hidden" name="currency_code" value="USD">

* <input type="hidden" name="item_name" value="Your testGods order">

* <input type="hidden" name="amount" value ="OrderAmount">

* <input type="hidden" name="test_ipn" value="1">

* <input type="hidden" name="rm" value="2">

<input type="hidden" name="notify_url" value="http://192.168.101.90:8013/Thanks.aspx">

<input type="hidden" name="lc" value="GB">

<input type="hidden" name="cbt" value="Click Here to Complete Order">

* <input type="hidden" name="return" value="http://192.168.101.90:8013/Thanks.aspx">

<input type="hidden" name="cancel_return" value="http://192.168.101.90:8013/Cancel.aspx">

<script type="text/javascript" language="JavaScript">document.order.submit();script>

form>

From the above list, the fields marked as * are the minimum required fields. Out of which the "test_ipn" variable is required only during the test mode. When making live this variable should be removed. In the

tag, the value action="https://www.sandbox.paypal.com/cgi-bin/webscr" - this url is meant for test mode. When making live this url needs to be changed to action="https://www.paypal.com/cgi-bin/webscr". The testing environment is termed as "sandbox environment".

Sandbox Environment :

- Now, as mentioned in the very first sentence when the customer is taken to the paypal website - the customer is prompted for either payment through paypal account or through credit card (if not having a paypal account).

- During sandbox environment we have to create some test accounts such as "personal" accounts and "business" accounts. A “Personal” account means the customer accounts that can make payment through paypal during sandbox environment. "Business" account means the client account/merchant account from whom the customer is purchasing the products.

- In order to create "personal" and "business" accounts we need to signup with https://developer.paypal.com. After signing up with developer.paypal we can create/manage sandbox accounts using this login account.

- To create/manage sandbox accounts (i.e. personal and business accounts) login to https://developer.paypal.com.

- You can get information on how to create sandbox accounts from - https://www.paypal.com/en_US/pdf/PP_Sandbox_UserGuide.pdf

- Whenever a new "personal" or "business" account is created an e-mail is fired. This e-mail contains a confirmation link, by clicking on this link only the account is activated. As soon as we login to https://developer.paypal.com. we can see various tabs such as "Home”, "Sandbox", "Test Certificates", "Email" . We can access the e-mails by clicking on the Email tab.

- After creating a "personal" or "business" account, the next step is to "Add a Bank Account" and then "Add a Credit Card" for the "created"

account(s).

- To add a bank account or a credit card we need to login to the respective "personal" or "business" account. After signing in

Navigate to My Account > Profile. Under the Financial Information header, click the Bank Accounts link or Credit Cards link.

- While adding a bank account there are certain things to be kept in mind for some specific countries.

(Reference - https://www.paypal.com/en_US/pdf/PP_Sandbox_UserGuide.pdf)

- While adding a credit card, only add Visa cards.......because only VISA cards are valid in test mode.

- A credit card may have limitations of transactions upto certain amount. After that we need to add a new credit card number for that particular "personal" account.

- Imp : We need to have test credit card numbers to test the transactions for those who don’t have paypal account. To create such credit card numbers, login to any of the "personal" account created in sandbox - go through the normal process of adding a credit card. But most imp. thing to be kept in mind is that as soon as the auto-generated credit card number is displayed, just make note of that credit card number and don't click on the "Add Card" button.......instead click on "Cancel" button otherwise that particular card number will be valid for that particular personal account and not available for non-paypal account holders. And this auto-generated credit card number can be used to test transactions for non-paypal account holders.

- Note : While running the application in test mode you need to keep an instance of https://developer.paypal.com opened in a separate browser and also needs to be signed in with the login with which sandbox accounts were created. And need to check every 10-15 min. whether the session has expired. During test mode enter any of the "personal" accounts created in sandbox i.e. enter any of the personal account email id and password to do the transaction in test mode.

Making Live:

Following things need to be kept in mind :

1) Remove the "test_ipn" variable from the list of “paypal form variables".

2) In the tag, change the value of action="https://www.sandbox.paypal.com/cgi-bin/webscr" - this URL is meant for test mode. When making live this url needs to be changed to action="https://www.paypal.com/cgi-bin/webscr".

3) Change the value of the variable named "business" to the original value.

No comments:

Post a Comment