我正在尝试集成PayPal支付网关,以便用户可以每月通过我们的订阅计划订阅我们的服务,这就是我迄今为止所做的。
APIContext apiContext = new APIContext(clientId, clientSecret, executionMode);
Map<String, Object> response = new HashMap<>();
try {
Plan plan = new Plan();
plan.setId("P-51X5509888001534KW7C3GMI");
Agreement agreement = new Agreement();
agreement.setPlan(plan);
agreement.setName("Orion Agreement");
agreement.setDescription("Plan creation Agreement");
agreement.setStartDate("2019-08-01T00:00:01Z");
//Now Create an object of credit card and add above details to it
//Address for the payment
Address billingAddress = new Address();
billingAddress.setCity("Los Angeles");
billingAddress.setCountryCode("US");
billingAddress.setLine1("Aplha street line 1");
billingAddress.setLine2("Beta street line 2");
billingAddress.setPostalCode("9001");
billingAddress.setState("Calofornia");
//This is only for users without paypal account
CreditCard card = new CreditCard();
card.setBillingAddress(billingAddress);
card.setCvv2("123");
card.setExpireMonth(9);
card.setExpireYear(2021) ;
card.setFirstName("Red");
card.setLastName("John");
card.setNumber("2221000000000009");
card.setType("mastercard");
// Now we need to specify the FundingInstrument of the Payer
// for credit card payments, set the CreditCard which we made above
FundingInstrument fundInstrument = new FundingInstrument();
fundInstrument.setCreditCard(card);
// The Payment creation API requires a list of FundingIntrument
List<FundingInstrument> fundingInstrumentList = new ArrayList<>();
fundingInstrumentList.add(fundInstrument);
Payer payer = new Payer();
payer.setPaymentMethod("credit_card");
payer.setFundingInstruments(fundingInstrumentList);
agreement.setPayer(payer);
ShippingAddress shippingAd = new ShippingAddress();
shippingAd.setLine1("111 First Street");
shippingAd.setCity("Saratoga");
shippingAd.setState("CA");
shippingAd.setPostalCode("95070");
shippingAd.setCountryCode("US");
Agreement agreementPlan = null;
try {
agreementPlan = agreement.create(apiContext);
} catch (Exception e) {
// TODO Auto-generated catch block
log.info("setupPlan error - " + e.toString());
e.printStackTrace();
}
response.put("redirectURL", agreementPlan);
} catch (Exception e) {
log.error("Exception in createAgreement {}", e);
}
return response;
我能够为拥有PayPal帐户的用户创建订阅。但是对于想要使用借记卡/信用卡付款的用户,我无法创建订阅。
我想知道到目前为止我实施的任何内容都是正确的,如果我错过了任何内容,请告诉我。
贝宝技术支持团队告诉我启用贝宝支付专业版,我已经为一个帐户启用了它。
这需要PayPal付款专业版, 计费计划和协议 API 现在也已弃用,对于订阅,您应该使用PayPal订阅 API,它支持通过卡订阅也通过PayPal,
集成指南:https://developer.paypal.com/docs/subscriptions/integrate/#
API 文档:https://developer.paypal.com/docs/api/subscriptions/v1/