[英]Card payment Using PayPal android
我們可以用信用卡付款來實現Paypal嗎? 例如,某人沒有貝寶帳戶,因此他/她可以使用借記卡或信用卡支付。 有什么辦法可以用卡來實現貝寶。 請幫忙。
嗨,我知道我回答這個問題很晚了,但是肯定會在他們的應用程序中實現Paypal的人們會從中受益! 適用於Paypal的Android SDK不支持信用卡付款,但是可以使用“ Rest API sdk for Paypal”功能。 包括在build.gradle中:編譯“ 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,以從用戶那里獲取任何物品,價格,信用卡詳細信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.