0
votes

I am trying to Integrate paypal payment gateway so that users can subscribe to our service through our subscription plans on a monthly basis and this is what I have doe so far.

        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;

I was able to create a subscription for the user who has the paypal account. But For the users who want to pay from their debit/credit card, I was not able to create a subscription.

I want to know whatever I have implemented so far is proper, If I have missed anything please let me know.

Paypals Technical support team told me to enable paypals payment pro , Which I have enabled for a account.

1

1 Answers

0
votes

@Thejas, That required Paypal Payment Pro, Also the billing plan and agreement API is deprecated now, For Subscription you should use Paypal Subscription API, It supports subscription via card also via Paypal,

Integration guide: https://developer.paypal.com/docs/subscriptions/integrate/#

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