我正在使用商家API,后面跟着此链接PayPal Integration guide
maven依赖,
<dependency>
<groupId>com.paypal.sdk</groupId>
<artifactId>merchantsdk</artifactId>
<version>2.6.109</version>
</dependency>
我的实现如下,
CreateRecurringPaymentsProfileReq createRecurringPaymentsProfileReq = new CreateRecurringPaymentsProfileReq();
CreateRecurringPaymentsProfileRequestType createRecurringPaymentsProfileRequest = new CreateRecurringPaymentsProfileRequestType();
RecurringPaymentsProfileDetailsType recurringPaymentsProfileDetails = new RecurringPaymentsProfileDetailsType();
recurringPaymentsProfileDetails.setBillingStartDate(formatterR.format(new Date()));
recurringPaymentsProfileDetails.setSubscriberName(subs.getFirstName()+" "+subs.getLastName());
BasicAmountType billingAmount = new BasicAmountType(CurrencyCodeType.USD, subs.getAmount().toString());
BillingPeriodDetailsType paymentPeriod = new BillingPeriodDetailsType(
BillingPeriodType.MONTH, Integer.parseInt("12"), billingAmount);
ScheduleDetailsType scheduleDetails = new ScheduleDetailsType("description", paymentPeriod); // description, paymentPeriod object
CreateRecurringPaymentsProfileRequestDetailsType createRecurringPaymentsProfileRequestDetails = new CreateRecurringPaymentsProfileRequestDetailsType(
recurringPaymentsProfileDetails, scheduleDetails);
AddressType addressType = new AddressType();
addressType.setStateOrProvince(subs.getState());
addressType.setCityName(subs.getCity());
addressType.setCountryName(subs.getCountry());
PersonNameType personName = new PersonNameType();
personName.setFirstName(subs.getFirstName());
personName.setLastName(subs.getLastName());
PayerInfoType payerInfoType = new PayerInfoType();
payerInfoType.setAddress(addressType);
payerInfoType.setPayerName(personName);
CreditCardDetailsType creditCard = new CreditCardDetailsType();
//creditCard.setCreditCardType(CreditCardTypeType.VISA);
// Credit Card Number
creditCard.setCreditCardNumber(subs.getCreditCardNo());//4442662639546634
// Credit Card Expiration Month
creditCard.setExpMonth(Integer.parseInt(subs.getExpirationDate().split("/")[0]));//Integer.parseInt("12")
// Credit Card Expiration Year
creditCard.setExpYear(Integer.parseInt(subs.getExpirationDate().split("/")[1]));//Integer.parseInt("2016")
creditCard.setCVV2(subs.getCardCode());
creditCard.setCardOwner(payerInfoType);
createRecurringPaymentsProfileRequestDetails.setCreditCard(creditCard);
createRecurringPaymentsProfileRequest
.setCreateRecurringPaymentsProfileRequestDetails(createRecurringPaymentsProfileRequestDetails);
createRecurringPaymentsProfileReq
.setCreateRecurringPaymentsProfileRequest(createRecurringPaymentsProfileRequest);
PayPalAPIInterfaceServiceService service = null;
try {
service = new PayPalAPIInterfaceServiceService(sdkConfig);
} catch (Exception e) {
LOGGER.info("Error Message : " + e.getMessage());
}
CreateRecurringPaymentsProfileResponseType createRecurringPaymentsProfileResponse = null;
try {
// ## Making API call
// Invoke the appropriate method corresponding to API in service
// wrapper object
createRecurringPaymentsProfileResponse = service
.createRecurringPaymentsProfile(createRecurringPaymentsProfileReq);
} catch (Exception e) {
LOGGER.info("Error Message : " + e.getMessage());
}
// ## Accessing response parameters
// You can access the response parameters using getter methods in
// response object as shown below
// ### Success values
if (createRecurringPaymentsProfileResponse.getAck().getValue()
.equalsIgnoreCase("success")) {
// A unique identifier for future reference to the details of
// this recurring payment.
LOGGER.info("Profile ID:"
+ createRecurringPaymentsProfileResponse
.getCreateRecurringPaymentsProfileResponseDetails()
.getProfileID());
return "approved";
}
// ### Error Values
// Access error values from error list using getter methods
else {
List<ErrorType> errorList = createRecurringPaymentsProfileResponse
.getErrors();
LOGGER.info("API Error Message : "
+ errorList.get(0).getLongMessage());
return "error";
}
返回如下,
Sep 02, 2014 12:16:37 PM com.paypal.core.LoggingManager log
INFO:2014-09-02T06:46:37ZFailure6836cf5983224Start Date is requiredSubscription start date is required11549Error109.012566246 [INFO] [http-8080-6 12:16:37](TestPayment.java:subscriptionPayment:645)API错误消息:订阅开始日期是必需的
任何人,请帮我解决这个问题......