Osama's Weblog

The place where you get updated!
  • rss
  • Home
  • Who am I?
  • RSS Feeds

Paypal X toolkit for Force.com

Osama | July 19, 2010

Last month Salesforce.com and PayPal announced Paypal X toolkit for Force.com Platform.

PayPal, as everybody knows is the most commonly used payment gateway in e-commerce world. The important points about PayPal are:

  • Facilitates payments
  • Pay anyone, receive from anyone
  • Account management
  • Tools for information and reporting

PayPal provides its APIs for integration with other e-commerce websites. They recently launched few changes in their system which are :

  • Pre-approval APIs
  • Refund
  • Convert Currency
  • Parallel Payments
  • Chained Payments

Using Parallel payments, you can split a single payment to any number of receivers. For example, a person purchases different items from different sellers. The person doesn’t have to arrange separate transactions for each seller. What he can do is just arrange a single payment which can be distributed among all the sellers. Isn’t it great?

Using Chained payments, you can send one payment to specific merchant who can further sends the payment after keeping his share. For example, you buy a product through a sales rep of an organization. You can arrange a chained payment for this purpose. You will pay to the sales rep and which will be forwarded to the organization’s account after the share of sales rep is deducted.

Force.com PayPal X toolkit is a set of apex classes for accessing API more easily. You can access them through force.com IDE after installing them into your organization. It takes care of transport . It securely manages API credentials. There is a custom object where you store your API credentials. It also supports adaptive accounts. It is easy to access PayPal sandobx sandbox, beta and live environments.
To access it, sign up on X.com. Obtain application ID from MyApps page. Now, create PayPal sandbox test account and signup on  http://developer.paypal.com. Now, Create test accounts for sandbox and obtain API credentials.

Install PayPal X toolkit from code share.

There are sample codes available for every kind of request that PayPal supports.
Now you don’t have to waste your time in writing custom code to integrate PayPal into your system. Just modify the template classes in the toolkit (which is usually the change in API credentials and some other information as required).

More info on this can be found at webinar by salesforce.com.

  • Share/Bookmark
Comments
No Comments »
Categories
APEX, General, salesforce
Tags
force.com, paypal, PayPal X, salesforce
Comments rss Comments rss
Trackback Trackback

Paypal integration in Apex

Osama | December 23, 2009

Payment gateways are parimary requiremnt in most of the business application these days. Applications building up on force.com platform require payment gateways.

Integration of paypal seems to be a very common issue. One of my readers asked me to write the code to integrate paypal with apex.

Below I am writing the code which I wrote for a project. I hope this will help many of the apex developers. This particular method is for DoDirectPayment method.

public class PayPalApi
{
public static String result {set;get;}
public static String makeCallout(String amount, String shipToName, String shipToStreet1, String shipToStreet2, String shipToCity, String shipToState, String shipToPostalCode, String shipToCountry, String creditCardType, String creditCardNumber, String expMonth, String expYear, String payerFName, String payerLName, String payerCountry, String payerStreet1, String payerStreet2, String payerCity, String payerState, String payerPostalCode, String CVV2Number)
{ // Instantiate a new http object
Http h = new Http();
// Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
HttpRequest req = new HttpRequest();
// The webservice url - Pass in the endpoint to be used using the string url
String url = 'https://api-3t.sandbox.paypal.com/2.0/';
String soapXML;

soapXML =  '<soap:Envelope xmlns:soap=' + '\'' + 'http://schemas.xmlsoap.org/soap/envelope/'  + '\'' + ' xmlns:xsi=' + '\''+ 'http://www.w3.org/2001/XMLSchema-instance'  + '\'' + ' xmlns:xsd=' + '\''+ 'http://www.w3.org/2001/XMLSchema' + '\'' + '>';
soapXML += '<soap:Header><RequesterCredentials xmlns="urn:ebay:api:PayPalAPI"><Credentials xmlns="urn:ebay:apis:eBLBaseComponents">';
soapXML += '<Username>PAYPAL_USER_NAME</Username><ebl:Password xmlns:ebl="urn:ebay:apis:eBLBaseComponents">';
soapXML += 'PAYPAL_PASSWORD</ebl:Password><Signature>PAYPAL_SIGNATURE</Signature>';
soapXML += '</Credentials></RequesterCredentials></soap:Header><soap:Body><DoDirectPaymentReq xmlns="urn:ebay:api:PayPalAPI">';
soapXML += '<DoDirectPaymentRequest><Version xmlns="urn:ebay:apis:eBLBaseComponents">1.00</Version>';
soapXML += '<DoDirectPaymentRequestDetails xmlns="urn:ebay:apis:eBLBaseComponents">';
soapXML += '<PaymentAction>Sale</PaymentAction><PaymentDetails><OrderTotal currencyID="USD">' + amount + '</OrderTotal>';
soapXML += '<ShipToAddress><Name>' + shipToName + '</Name><Street1>' + shipToStreet1 + '</Street1><Street2>' +shipToStreet2 + '</Street2>';
soapXML += '<CityName>' + shipToCity + '</CityName><StateOrProvince>' + shipToState + '</StateOrProvince><PostalCode>' + shipToPostalCode + '</PostalCode>';
soapXML += '<Country>' + shipToCountry + '</Country></ShipToAddress>';
soapXML += '</PaymentDetails><CreditCard><CreditCardType>' + creditCardType + '</CreditCardType><CreditCardNumber>' + creditCardNumber + '</CreditCardNumber>';
soapXML += '<ExpMonth>' + expMonth + '</ExpMonth><ExpYear>' + expYear + '</ExpYear><CardOwner><PayerStatus>verified</PayerStatus><Payer>bgiles@ddd.com</Payer>';
soapXML += '<PayerName><FirstName>' + payerFName+ '</FirstName><LastName>' + payerLName + '</LastName></PayerName><PayerCountry>' + payerCountry + '</PayerCountry>';
soapXML += '<Address><Street1>' + payerStreet1 + '</Street1><Street2>' + payerStreet2 + '</Street2><CityName>' + payerCity + '</CityName>';
soapXML += '<StateOrProvince>' + payerState + '</StateOrProvince><Country>' + payerCountry + '</Country><PostalCode>' + payerPostalCode + '</PostalCode></Address>';
soapXML += '</CardOwner><CVV2>' + CVV2Number + '</CVV2></CreditCard></DoDirectPaymentRequestDetails>';
soapXML += '</DoDirectPaymentRequest></DoDirectPaymentReq></soap:Body></soap:Envelope>';

req.setBody(soapXML);
req.setEndpoint(url);
req.setMethod('POST');
req.setHeader('Content-length', '1753' );
req.setHeader('Content-Type', 'text/xml;charset=UTF-8'); req.setHeader('SOAPAction','');
req.setHeader('Host','api-aa.sandbox.paypal.com');

HttpResponse res = h.send(req);
String xml = res.getBody();

XmlStreamReader reader = res.getXmlStreamReader();
result = readXMLResponse(reader,'Ack');
return result;
}
public static String readXMLResponse(XmlStreamReader reader, String sxmltag)
{
string retValue; // Read through the XML
while(reader.hasNext())
{
if (reader.getEventType() == XmlTag.START_ELEMENT)
{
if (reader.getLocalName() == sxmltag) {
reader.next();
if (reader.getEventType() == XmlTag.characters)
{ retValue = reader.getText();
}
}
} reader.next();
}
return retValue;
}
}

Other paypal methods dont require this type of coding because they are mostly redirected to paypal website. If you need further help, feel free to ask questions.

P.S: This code is completely working. You just have to replace with your credentials.

  • Share/Bookmark
Comments
No Comments »
Categories
APEX
Tags
APEX, DoDirectPayment, paypal, VisualForce, web service
Comments rss Comments rss
Trackback Trackback

My status

Categories

  • .NET
  • APEX
  • consulting
  • General
  • Oracle CRM on Demand
  • salesforce
  • Uncategorized
  • VisualForce

MM Did You Know?

MM Did You Know? Wordpress plugin by Milan Milosevic. More...
Plugin by mmilan

Its all about cloud

Salesforce

.NET .NET 4.0 beta actionFunction actionSupport administrator android APEX Apex variable API button certification cloud computing consulting controller custom DoDirectPayment force.com GET goggles google html images input inputField JavaScript jquery master-detail matcher Parallel Programming parameters pattern paypal query string REGEX regular expression salesforce search url variable Visual Force VisualForce Visual Studio vmware web service XML PARSING DOM SAX STAX

WP Cumulus Flash tag cloud by Roy Tanck and Luke Morton requires Flash Player 9 or better.

My Tweets

Error: Please make sure the Twitter account is public.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox