Paypal 101

Paypal – Its a name vaguely familiar to almost everyone with a Credit Card & the zeal to e-burn some of mummy’s hard earned money.

From the user point of view (POV), its all fun provided it doesn’t get you grounded.

From the developer POV, its not always sunny in California.

For a newbie, its nothing short of ending up on a blind date with your high school crush “on a bad hair day”. Need I say more.

Lets cut through the chase, shall we?

Points to consider:-

There are two apis namely

a) Name-Value Pair Interface (NVP)

b) SOAP Interface

What to pick?

To be blunt , depends entirely on the client’s requirement.

In my case it was NVP.

Here it goes,

1)Before starting out , signup for a test account -> https://developer.paypal.com

2)That being done, sign in .

3)Now we need to get hold of a test account

Click on

“Create a preconfigured account”.

Choose account type.

If you want to test payments made to an account , go for

“Seller (Use to represent yourself as the merchant)”

or

“Website Payments Pro (Use to represent yourself as a merchant using Pro) ” depending on what type of account the client has.

Next get your api keys. On the home click on “Api Credentials”. Save the keys in a seperate file , api.php. Remember not to keep api.php on the root directory of the production server for security reasons.

4)Download the sample NVP code from https://cms.paypal.com/cms_content/US/en_US/files/developer/NVPcodesamples.zip

This will get you & the naming convention in the same page.

5)Get yourslelf a form with all the fields that you need in addition to the ones that paypal needs.

The primary fields for paypal are firstName, lastName, email, creditCardType, creditCardNumber, expDateMonth, expDateYear, cvv2Number plus the billing address info.

Post the content to same / (preferably) another page. Lets call it process.php . Get hold of all the posted data. Urlencode all the info that paypal api needs.

Require the file CallerService.php.

In the file CallerService.php, require the file api.php after removing the variables in api.php from constants.php in defining section.

6)Paypal provides a variety of services like Direct Checkout , Express Checkout., Recurring Payment ,

3D secure payment etc. Its a pretty long list.

Lets say we need to bill the person for a service over a period of time.

One of the ways to do so is to make a direct checkout followed by a recurring profile , which will deduct the amount from the user after a predefined interval.

7)Before making the api call , we need to make the string to be forwarded .
It would look something like this

$nvpstr="&PAYMENTACTION=$paymentType&AMT=$amount&CREDITCARDTYPE=$creditCardType&ACCT=$creditCardNumber&EXPDATE=".$padDateMonth.$expDateYear."&CVV2=$cvv2Number&FIRSTNAME=$firstName&LASTNAME=$lastName&STREET=$address1&CITY=$city&STATE=$state"."&ZIP=$zip&COUNTRYCODE=US&CURRENCYCODE=$currencyCode";

 
For direct payment, payment type can be sale / authorize.

Now we are all set for the api call.

$resArray=hash_call("doDirectPayment",$nvpstr);

 
Grab hold of that “ACK” part of the response.

If its “success”, then the payment was successfully carried out. You can cross check by checking out the “history” in the test account.

Its a handful , aint it?

But the task is not done.
We still need the recurring profile to bill the user automatically for the stipulated time period.

We do what we did before, create the string & make the api call.

Here is the string

$nvpstr="&AMT=$amount&CREDITCARDTYPE=$creditCardType&ACCT=$creditCardNumber&EXPDATE=". $padDateMonth.$expDateYear."&CVV2=$cvv2Number&FIRSTNAME=$firstName&LASTNAME=$lastName&STREET=$address1&CITY=$city&STATE=$state".

"&ZIP=$zip&COUNTRYCODE=US&CURRENCYCODE=$currencyCode&PROFILESTARTDATE=$profileStartDate&DESC=$profileDesc&BILLINGPERIOD=$billingPeriod&BILLINGFREQUENCY=$billingFrequency";

Make the call

$resArray=hash_call("CreateRecurringPaymentsProfile",$nvpstr);

Get the response

$ack = $resArray["ACK"];

if $ack == 'success'{You are the man.}

else{debug dude!!!}

Happy Paypallin

150 150 Burnignorance | Where Minds Meet And Sparks Fly!