0

我们可以用卡支付来实施 Paypal。例如,某人没有贝宝帐户,因此他/她可以使用借记卡或信用卡付款。有没有办法用卡实现贝宝。请帮忙。

4

1 回答 1

1

嗨,我知道我回答这个问题已经很晚了,但是在他们的应用程序中实施 Paypal 的人肯定会从中受益!适用于 Paypal 的 Android SDK 不支持卡支付,但是“适用于 Paypal 的 Rest API sdk”具有该功能。将此包含在您的 build.gradle 中: compile 'com.paypal.sdk:rest-api-sdk:1.2.5'

然后尝试以下方法:

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 以获取任何项目、其定价、用户信用卡详细信息。

于 2015-08-24T07:00:44.650 回答