程序中的支付流程中:
1.浏览商品
2.把要买的商品加入购物车
3.把购物车中的商品信息和用户信息和支付方式等信息发送到自己服务器,服务器处理商品信息生成订单,并返回”支付串”给客户端
4.客户端拿着“支付串”,调用第三方服务(支付宝、微信、银联、paypal等)完成支付
5.处理支付结果(成功、失败、取消)
l 同步返回:支付后通知我们的客户端
l 异步通知:支付后通知我们的服务端
以上就是一般的移动支付的基本流程了,下面看这几个支付平台的详细介绍
android移动支付——支付宝支付
android移动支付——微信支付
android移动支付——银联支付
android移动支付——PayPal支付
PayPal支付
上面的支付方式都是中国境内常用的支付方式,那如果想用境外的支付呢,无疑Paypal是一个不错的选择,下面来接入它:
1. 注册PayPal开发者账号,并且添加你的APP
首先我们要去PayPal的开发者平台注册账号,并且创建应用,获取Client ID
2. 可以在PayPal的github上看到它一些详细的介绍
可以拿到依赖
,配置一下你的工程:
compile(‘com.paypal.sdk:paypal-android-sdk:2.15.1’)
{ excludegroup: ‘io.card’ }//禁止通过信用卡直接支付,如果不禁止可以直接去掉这一句
3. 集成的最低版本
由于PayPal默认集成的最低版本是minSdkVersion 16或者更高,所以你的AS编译版本低于这个版本的时候,AS会提示你编译不通过,报错等等,这是你需要在清单文件AndroidMainfest强制一下你需要的版本下编译:
<uses-sdkandroid:minSdkVersion=“INSERT_YOUR_DESIRED_minSdkVersion_HERE” tools:overrideLibrary=“com.paypal.android.sdk.payments”/>
4. 在你需要支付的页面配置支付环境(或者在你的基类里面配置)
这里可以到官网上申请商户和个人的沙盒测试账号进行测试
// 配置各种支付类型,一般就沙盒测试的和正式的
privatestatic final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_NO_NETWORK;
// note that these credentialswill differ between live & sandbox environments.
// 这是在第一步时候注册创建得来的Client ID
private static final String CONFIG_CLIENT_ID = “credentials from developer.paypal.com”;
private static final int REQUEST_CODE_PAYMENT = 1;
private static final int REQUEST_CODE_FUTURE_PAYMENT = 2;
private static final int REQUEST_CODE_PROFILE_SHARING = 3;
private static PayPalConfigurationconfig = new PayPalConfiguration()
.environment(CONFIG_ENVIRONMENT)
.clientId(CONFIG_CLIENT_ID)
// The following are only used inPayPalFuturePaymentActivity.
// 下面的这些都是要用到授权支付才用到的,不用就注释掉可以了
.merchantName(“Example Merchant”)
.merchantPrivacyPolicyUri(Uri.parse(“https://www.example.com/privacy”))
.merchantUserAgreementUri(Uri.parse(“https://www.example.com/legal”));
5. 在类的onCreate里面调起支付服务
Intentintent = new Intent(this, PayPalService.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
startService(intent);
6. 在需要支付的地方调起支付功能,这里有两种类型
publicvoid onBuyPressed(View pressed) {
/*
* PAYMENT_INTENT_SALE will cause thepayment to complete immediately.
* Change PAYMENT_INTENT_SALE to
* - PAYMENT_INTENT_AUTHORIZE to only authorize payment and capture fundslater.
* - PAYMENT_INTENT_ORDER to create a payment for authorization and capture
* later via calls from your server.
*
* Also, to include additionalpayment details and an item list, see getStuffToBuy() below.
*/
PayPalPayment thingToBuy =getStuffToBuy(PayPalPayment.PAYMENT_INTENT_SALE);
/*
* See getStuffToBuy(…) for examplesof some available payment options.
*/
Intent intent = new Intent(SampleActivity.this, PaymentActivity.class);
// send the same configuration for restartresiliency
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
startActivityForResult(intent, REQUEST_CODE_PAYMENT);
}
private PayPalPayment getThingToBuy(String paymentIntent) {
return new PayPalPayment(new BigDecimal(“0.01”), “USD”, “sample item”,
paymentIntent);
}
/*
* This method shows use of optionalpayment details and item list.
*/
private PayPalPayment getStuffToBuy(String paymentIntent) {
//— include an item list, payment amountdetails
PayPalItem[] items =
{
new PayPalItem(“sample item #1”, 2, new BigDecimal(“87.50”), “USD”,
“sku-12345678”),
new PayPalItem(“free sample item #2”, 1, new BigDecimal(“0.00”),
“USD”, “sku-zero-price”),
new PayPalItem(“sample item #3 with a longername”, 6, new BigDecimal(“37.99”),
“USD”, “sku-33333”)
};
BigDecimal subtotal = PayPalItem.getItemTotal(items);
BigDecimal shipping = new BigDecimal(“7.21”);
BigDecimal tax = new BigDecimal(“4.67”);
PayPalPaymentDetails paymentDetails = new PayPalPaymentDetails(shipping, subtotal, tax);
BigDecimal amount =subtotal.add(shipping).add(tax);
PayPalPayment payment= new PayPalPayment(amount, “USD”, “sample item”, paymentIntent);
payment.items(items).paymentDetails(paymentDetails);
ew PayPalPaymentDetails(shipping, subtotal, tax);
BigDecimal amount =subtotal.add(shipping).add(tax);
PayPalPayment payment= new PayPalPayment(amount, “USD”, “sample item”, paymentIntent);
payment.items(items).paymentDetails(paymentDetails);