首页 文章

卡支付使用PayPal android

提问于
浏览
0

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

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,以获取项目,定价,用户信用卡详细信息 .

相关问题