Paypal provides two ways to invoke their API's- Through the signature base and another is through certificates.
1. Signature based: For signature based the mandatory parameters are:
- API Username
- API password
- API signature
2. Certificate based: Mandatory parameters for this approach are:
- API Username
- API password
- API certificate
- API certificate key
Generate API Signature and Certificate
You need to generate the signature or certificate depending upon the approach you are going to use. The process for both is nearly same. Login to your Paypal sandbox account. If you don't have the valid account, register as new user. For more details for generating certificates and signatures can be obtained from here.
Code snippet to be integrated
1. Define property file
- Property file for Signature based approach
acct1.UserName = ****-facilitator_api1.gmail.com
acct1.Password = 348889***
acct1.Signature = W19Jweloyt7bsmlaqzxrL7vYoFV*****
- Property file for Certificate based approach
acct1.UserName = ****-facilitator_api1.gmail.com
acct1.Password = 348889***
acct1.CertPath=/opt/tmp/paypal_cert.p12
acct1.CertKey=keyvalue
- Common properties for both the approaches
service.EndPoint.PayPalAPI=https://api.sandbox.paypal.com/2.0/
service.EndPoint.PayPalAPIAA=https://api.sandbox.paypal.com/2.0/
service.EndPoint.Permissions=https://svcs.sandbox.paypal.com/
http.ConnectionTimeOut=5000
2. Initialize properties: here we are taking example of the certificate based approach
loadProperties(){
Properties PAYPAL_PROP = new Properties();
PAYPAL_PROP.put("acct1.UserName",readProperty("acct1.UserName"));
PAYPAL_PROP.put("acct1.Password",readProperty("acct1.Password"));
PAYPAL_PROP.put("acct1.CertKey", readProperty("acct1.CertKey"));
PAYPAL_PROP.put("acct1.CertPath", readProperty("acct1.CertPath"));
PAYPAL_PROP.put("service.EndPoint.PayPalAPI", readProperty("service.EndPoint.PayPalAPI"));
PAYPAL_PROP.put("service.EndPoint.PayPalAPIAA", readProperty("service.EndPoint.PayPalAPI"));
PAYPAL_PROP.put("service.EndPoint.Permissions", readProperty("service.EndPoint.Permissions"));
PAYPAL_PROP.put("http.ConnectionTimeOut", .readProperty("http.ConnectionTimeOut"));
}
3. Invoke API's: Sample code snippet in Java for doVoid request
DoVoid(String sAuthorizationId){
DoVoidReq doVoidReq = new DoVoidReq();
DoVoidRequestType doVoidRequest = new DoVoidRequestType(sAuthorizationId);
doVoidReq.setDoVoidRequest(doVoidRequest);
PayPalAPIInterfaceServiceService service = null;
service = new PayPalAPIInterfaceServiceService(PAYPAL_PROP);
DoVoidResponseType doVoidResponse = service.doVoid(doVoidReq);
}
Similarly you can invoke other Paypal API's using the above code.
1. Signature based: For signature based the mandatory parameters are:
- API Username
- API password
- API signature
2. Certificate based: Mandatory parameters for this approach are:
- API Username
- API password
- API certificate
- API certificate key
Generate API Signature and Certificate
You need to generate the signature or certificate depending upon the approach you are going to use. The process for both is nearly same. Login to your Paypal sandbox account. If you don't have the valid account, register as new user. For more details for generating certificates and signatures can be obtained from here.
Code snippet to be integrated
1. Define property file
- Property file for Signature based approach
acct1.UserName = ****-facilitator_api1.gmail.com
acct1.Password = 348889***
acct1.Signature = W19Jweloyt7bsmlaqzxrL7vYoFV*****
- Property file for Certificate based approach
acct1.UserName = ****-facilitator_api1.gmail.com
acct1.Password = 348889***
acct1.CertPath=/opt/tmp/paypal_cert.p12
acct1.CertKey=keyvalue
- Common properties for both the approaches
service.EndPoint.PayPalAPI=https://api.sandbox.paypal.com/2.0/
service.EndPoint.PayPalAPIAA=https://api.sandbox.paypal.com/2.0/
service.EndPoint.Permissions=https://svcs.sandbox.paypal.com/
http.ConnectionTimeOut=5000
2. Initialize properties: here we are taking example of the certificate based approach
loadProperties(){
Properties PAYPAL_PROP = new Properties();
PAYPAL_PROP.put("acct1.UserName",readProperty("acct1.UserName"));
PAYPAL_PROP.put("acct1.Password",readProperty("acct1.Password"));
PAYPAL_PROP.put("acct1.CertKey", readProperty("acct1.CertKey"));
PAYPAL_PROP.put("acct1.CertPath", readProperty("acct1.CertPath"));
PAYPAL_PROP.put("service.EndPoint.PayPalAPI", readProperty("service.EndPoint.PayPalAPI"));
PAYPAL_PROP.put("service.EndPoint.PayPalAPIAA", readProperty("service.EndPoint.PayPalAPI"));
PAYPAL_PROP.put("service.EndPoint.Permissions", readProperty("service.EndPoint.Permissions"));
PAYPAL_PROP.put("http.ConnectionTimeOut", .readProperty("http.ConnectionTimeOut"));
}
3. Invoke API's: Sample code snippet in Java for doVoid request
DoVoid(String sAuthorizationId){
DoVoidReq doVoidReq = new DoVoidReq();
DoVoidRequestType doVoidRequest = new DoVoidRequestType(sAuthorizationId);
doVoidReq.setDoVoidRequest(doVoidRequest);
PayPalAPIInterfaceServiceService service = null;
service = new PayPalAPIInterfaceServiceService(PAYPAL_PROP);
DoVoidResponseType doVoidResponse = service.doVoid(doVoidReq);
}
Similarly you can invoke other Paypal API's using the above code.

No comments:
Post a Comment