卡付款使用贝宝机器人 [英] Card payment Using PayPal android

查看:174
本文介绍了卡付款使用贝宝机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以用卡支付实现贝宝。例如有人没有PayPal帐户,这样他/她可以支付使用借记卡或信用卡。有什么办法来实现与贝宝卡。
请帮助。

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. Please help.

推荐答案

您好我知道我是很晚回答这个问题,但肯定在他们的应用中实施乡亲贝宝将从此获益!
贝宝的Andr​​oid SDK不支持卡付款,但有REST API SDK贝宝有能力。在你的build.gradle包括这样的:编译com.paypal.sdk:REST的API-SDK:1.2.5

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:

public static final String  CLIENT_ID = "AQkquBDf1zctJOWGKWUEtKXm6qVhueUEMvXO_-MCI4DQQ4-LWvkDLIN2fGsd";
public static final String  CLIENT_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
     */
    public static final String getAccessToken(String clientId, String clientSecret){
        Log.i(TAG,"GetAccessToken called");
        String accessToken = "";
        long expiresIn;

        try {
            OAuthTokenCredential oAuthTokenCredential = new OAuthTokenCredential(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
         */
        public static final String makeDirectPayment(){

            String accessToken = getAccessToken(Constants.CLIENT_ID, Constants.CLIENT_SECRET);
            String message = "";
            if (accessToken != null && !accessToken.equals("")){
                APIContext apiContext = new APIContext(accessToken);
                apiContext.setConfigurationMap(getSdKConfig());

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

                FundingInstrument fundingInstrument = new FundingInstrument();
                fundingInstrument.setCreditCard(creditCard);

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

                Payer payer = new Payer();
                payer.setFundingInstruments(fundingInstrumentList);
                payer.setPaymentMethod("credit_card");

                Amount amount = new Amount();
                amount.setCurrency("EUR");
                amount.setTotal("50");

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

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

                Payment payment = new Payment();
                payment.setIntent("sale");
                payment.setTransactions(transactionList);
                payment.setPayer(payer);

                try {
                    Payment createdPayment = 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;
        }

请注意为了简单起见,我用静态的一切,但你可以保持自己的UI获得任何项目,它的定价,信用卡信息从用户。

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.

这篇关于卡付款使用贝宝机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆