Paypal gives a vast support for online payment, everything is been documented in nice way but we have to Google for better results for your payment to get in your control(other than standard payments).

There are two API’s provided by pay pal:

  1. Rest(


  2. Classic(


The classic contains many product listed in the doc. From that list i am explaining the recurring payment.

First we need merchant api. Simply add below codes in your build config of Grails project.

compile ('com.paypal.sdk:merchantsdk:2.5.106'){
excludes "commons-codec"

Need a developers account. (Create here)

Details of code can be found at  Dev tools

Codes are below with explanations.

RecurringPaymentsProfileDetailsType profileDetails = new RecurringPaymentsProfileDetailsType(Start-date);

Recurring profile start date is added here. When the date of recurring starts the first payment is made by paypal.

BasicAmountType paymentAmount = new BasicAmountType(CurrencyCodeType.USD, "1.0");
BillingPeriodType period = BillingPeriodType.fromValue("Day");
int frequency = 10;
BillingPeriodDetailsType paymentPeriod = new BillingPeriodDetailsType(period, frequency, paymentAmount);

In billing period details we need to add the time period can be day, month or year, the frequency i.e. the number of occurrence of the time period and last the payment amount.

ScheduleDetailsType scheduleDetails = new ScheduleDetailsType();
scheduleDetails.setDescription("recurring billing");

Simply adding the description for what the payment is about and setting the period.

CreditCardDetailsType creditCard = new CreditCardDetailsType();

Adding the valid credentials. Set proper card type, I have set for only visa here .

PayerInfoType payerInfoType=new PayerInfoType()
PersonNameType p=new PersonNameType()

The above codes set the payer name. These are not in the actual dev.tool documents.

CreateRecurringPaymentsProfileRequestDetailsType createRPProfileRequestDetails = new CreateRecurringPaymentsProfileRequestDetailsType(profileDetails, scheduleDetails);

From here the profile is created.

CreateRecurringPaymentsProfileRequestType createRPProfileRequest = new CreateRecurringPaymentsProfileRequestType();
CreateRecurringPaymentsProfileReq createRPPProfileReq = new CreateRecurringPaymentsProfileReq();

Now buyers information is set. We need to set the sellers account credentials. Which van be easily found at

Map<String, String> sdkConfig = new HashMap<String, String>();
sdkConfig.put("mode", "sandbox");
sdkConfig.put("acct1.UserName", "");
sdkConfig.put("acct1.Password", "WX4WTU3S8MY44S7F");
PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(sdkConfig);
CreateRecurringPaymentsProfileResponseType createRPProfileResponse = service.createRecurringPaymentsProfile(createRPPProfileReq);

These configurations are easy but i am explaning them also, first add the mode(Remember that sandbox mode is only user for testing and development, actual payment is done in live mode).

For username password and signature go to this link and open the facilitator profile and switch tab to API credentials.

Paypal responses as JSON

PROFILEID=I-X5626H5BY8A5 & PROFILESTATUS=ActiveProfile & TIMESTAMP=2015-03-29T16:37:00Z & CORRELATIONID=36742ed03cdb6 & ACK=Success & VERSION=104.0 & BUILD=15840636

Paypal generates a recurring profile id which comes in response with the acknowledgement.

After the code cooking is done start testing them. 😉