0
我們可以通過卡支付方式實現Paypal嗎?例如有人沒有貝寶賬戶,所以他/她可以使用借記卡或信用卡付款。有什麼辦法用卡實現paypal。 請幫忙。使用貝寶付款的卡支付方式android
我們可以通過卡支付方式實現Paypal嗎?例如有人沒有貝寶賬戶,所以他/她可以使用借記卡或信用卡付款。有什麼辦法用卡實現paypal。 請幫忙。使用貝寶付款的卡支付方式android
嗨,我知道我很晚回答這個問題,但肯定會在他們的應用程序中實現貝寶的人會從中受益! Paypal的Android SDK不支持卡付款,但是是「PayPal的Rest API sdk」有這項功能。在您的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;
}
注意爲簡單起見,我已經使用一切都是靜態的,但您可以維護自己的用戶界面以獲取任何項目,其定價,用戶的信用卡詳細信息。
使用沙盒,您可以創建一個模擬付款賬戶。看看這些鏈接http://www.paypalobjects.com/en_US/ebook/PP_Sandbox_UserGuide/test_user_setup.html http://www.webassist.com/support/documentation/how-tos/paypal_sandbox.php https://www.x.com/developers/paypal/documentation-tools/ug_sandbox#accounts – Lucifer
貝寶文檔涵蓋了所有這些信息。 – minhaz
@minhaz我使用該代碼,但它給我503錯誤。 – URAndroid