对于没有贝宝账户的用户,使用信用卡进行贝宝订阅

时间:2019-07-09 16:50:57

标签: paypal integration credit-card paypal-subscriptions

我正在尝试集成贝宝支付网关,以便用户可以通过我们的订阅计划每月订阅我们的服务,这是我到目前为止所做的。

        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帐户的用户创建订阅。但是对于想要通过借记卡/信用卡付款的用户,我无法创建订阅。

我想知道到目前为止我所实施的一切都是正确的,如果我错过了任何事情,请告诉我。

Paypals技术支持团队告诉我启用我已为帐户启用的paypals Payment pro。

1 个答案:

答案 0 :(得分:0)

@Thejas,这要求使用Paypal Payment Pro,而且现在不建议使用结算计划和协议API, 对于订阅,您应该使用Paypal订阅API,该API支持通过卡(也可以通过Paypal)进行订阅,

集成指南:https://developer.paypal.com/docs/subscriptions/integrate/#

API文档:https://developer.paypal.com/docs/api/subscriptions/v1/