Skip to content Skip to sidebar Skip to footer

Card Payment Using Paypal Android

Can we implement Paypal with a card payment. e.g. Somebody doesn't have paypal account so he/she can pay using debit or credit card. Is there any way to implement paypal with card.

Solution 1:

Hi I know I am very late to answer this question but surely folks implementing Paypal in their app will get benefit from this! Android SDK for Paypal does not support Card Payment but yes "Rest API sdk for Paypal" has the capability. Include this in your build.gradle: compile 'com.paypal.sdk:rest-api-sdk:1.2.5'

And then try the following method:

publicstaticfinalStringCLIENT_ID="AQkquBDf1zctJOWGKWUEtKXm6qVhueUEMvXO_-MCI4DQQ4-LWvkDLIN2fGsd";
publicstaticfinalStringCLIENT_SECRET="EL1tVxAjhT7cJimnz5-Nsx9k2reTKSVfErNQF-CmrwJgxRtylkGTKlU4RvrX";

/**
     * @method getAccessToken is used to get AccessToken for performing authorised transcations
     * @param clientId credential that we get when we register our application on https://developer.paypal.com/
     * @param clientSecret credential that we get when we register our application on https://developer.paypal.com/
     * @return String accessToken
     */publicstaticfinal String getAccessToken(String clientId, String clientSecret){
        Log.i(TAG,"GetAccessToken called");
        StringaccessToken="";
        long expiresIn;

        try {
            OAuthTokenCredentialoAuthTokenCredential=newOAuthTokenCredential(clientId, clientSecret, getSdKConfig());
            expiresIn = oAuthTokenCredential.expiresIn();
            accessToken = oAuthTokenCredential.getAccessToken();
             Log.i(TAG, "AccessToken: "+accessToken);
        } catch (PayPalRESTException e) {
            e.printStackTrace();
        }
        return accessToken;
    }

 /**
         * @method makeDirectPayment is used for making direct payment via credit cards. Customers who don't have paypal account can pay via this method.
         * @return String with Payment Id and Payment status
         */publicstaticfinal String makeDirectPayment(){

            StringaccessToken= getAccessToken(Constants.CLIENT_ID, Constants.CLIENT_SECRET);
            Stringmessage="";
            if (accessToken != null && !accessToken.equals("")){
                APIContextapiContext=newAPIContext(accessToken);
                apiContext.setConfigurationMap(getSdKConfig());

                CreditCardcreditCard=newCreditCard();
                creditCard.setType("visa");
                creditCard.setNumber("4446283280247004");
                creditCard.setExpireMonth(11);
                creditCard.setExpireYear(2019);
                creditCard.setFirstName("Test");
                creditCard.setLastName("Shopper");

                FundingInstrumentfundingInstrument=newFundingInstrument();
                fundingInstrument.setCreditCard(creditCard);

                List<FundingInstrument> fundingInstrumentList = newArrayList<>();
                fundingInstrumentList.add(fundingInstrument);

                Payerpayer=newPayer();
                payer.setFundingInstruments(fundingInstrumentList);
                payer.setPaymentMethod("credit_card");

                Amountamount=newAmount();
                amount.setCurrency("EUR");
                amount.setTotal("50");

                Transactiontransaction=newTransaction();
                transaction.setDescription("Creating Direct Payment with Credit Card");
                transaction.setAmount(amount);

                List<Transaction> transactionList = newArrayList<>();
                transactionList.add(transaction);

                Paymentpayment=newPayment();
                payment.setIntent("sale");
                payment.setTransactions(transactionList);
                payment.setPayer(payer);

                try {
                    PaymentcreatedPayment= payment.create(apiContext);

                    if (createdPayment != null){
                        Log.i(TAG,"Payment object: "+createdPayment.toJSON());
                        message = "Payment Id: " + createdPayment.getId() + " Payment status: "+createdPayment.getState();
                        Log.i(TAG, message);
                    }
                } catch (PayPalRESTException e) {
                    e.printStackTrace();
                }

            }
            return message;
        }

Note for simplicity I have used everything static but you can maintain your own UI to get no of items, its pricing, credit card details from user.

Post a Comment for "Card Payment Using Paypal Android"