因为最近项目中需要集成paypal,所以集成了一下,发现网上的有些文章过于老旧,所以自己写一篇踩坑记,首先是去官网申请账号,到时候会分配给你一个client_id

以上准备都做好了 就新建一个项目

引入paypel的包

compile('com.paypal.sdk:paypal-android-sdk:2.15.3')

{ exclude group: 'io.card' }// 如果不想支持信用卡支付 就加上这句话

新建一个activity 配置

private static PayPalConfiguration config =

new PayPalConfiguration()

.environment(PayPalConfiguration.ENVIRONMENT_SANDBOX)

.clientId("");

这里就输入你的client_id

3.然后在oncreate中开启服务

// 开启PayPal服务

Intent intent = new Intent(this, PayPalService.class);

intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, paypalConfig);

startService(intent);

4.买东西

public void onBuyPressed(View pressed) {

//创建支付对象,用于传过去给PayPal服务器进行收款

PayPalPayment thingToBuy = getThingToBuy(PayPalPayment.PAYMENT_INTENT_SALE);

Intent intent = new Intent(this, PaymentActivity.class);

intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, paypalConfig);

intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);

//这里直接调起PayPal的sdk进行付款操作

startActivityForResult(intent, 1);

}

//这里只传一个总价格或者单个产品的信息收款情况

private PayPalPayment getThingToBuy(String paymentIntent) {

return new PayPalPayment(new BigDecimal("0.01"), "USD", "sample item",

paymentIntent);

}

//这里是购买一系列产品创建购买对象

private PayPalPayment getStuffToBuy(String paymentIntent) {

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 longer name", 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);

//--- set other optional fields like invoice_number, custom field, and soft_descriptor

payment.custom("This is text that will be associated with the payment that the app can use.");

return payment;

}

5.接收回调

/**

* 接收支付结果的回调.

*/

@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

if (requestCode == 1 && resultCode == Activity.RESULT_OK) {

PaymentConfirmation confirm =

data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);

if (confirm != null) {

try {

//这里可以把PayPal带回来的json数据传给服务器以确认你的款项是否收到或者收全

//可以直接把 confirm.toJSONObject() 这个带给服务器,

//得到服务器返回的结果,你就可以跳转成功页面或者做相应的处理了

Log.i(TAG, confirm.toJSONObject().toString(4));

// confirm.toJSONObject().toString();

Log.i(TAG, confirm.getPayment().toJSONObject().toString(4));

Log.i(TAG, confirm.toJSONObject().toString());

} catch (JSONException e) {

Log.e(TAG, "an extremely unlikely failure occurred: ", e);

}

}

} else if (resultCode == Activity.RESULT_CANCELED) {

Log.i(TAG, "The user canceled.");

} else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {

Log.i(

TAG,

"An invalid Payment or PayPalConfiguration was submitted. Please see the docs.");

}

}

6.注销service

@Override

protected void onStop() {

stopService(new Intent(this, PayPalService.class));

super.onStop();

}

paypal android 教程,android端集成paypal相关推荐

  1. php集成paypal接口,PHP中集成PayPal标准支付,php集成paypal标准_PHP教程

    PHP中集成PayPal标准支付,php集成paypal标准 PayPal支付功能其实一直在更新文档和接口,这里说的是一个简单的支付功能大概流程如下 1,在网站的结账页面,设置一个提交到PayPal网 ...

  2. Xamarin Android教程Android基本知识版本介绍与系统介绍

    Xamarin Android教程Android基本知识版本介绍与系统介绍 Xamarin Android教程Android基本知识版本介绍与系统介绍,开发Andriod有时候不像iOS一样轻松,因为 ...

  3. android教程 - android ui 介绍,多图详解 “Android UI”设计官方教程

    我们曾经给大家一个<MeeGo移动终端设备开发UI设计基础教程>,同时很多朋友都在寻找Android UI开发的教程,我们从Android的官方开发者博客找了一份幻灯片,介绍了一些Andr ...

  4. flex+android+教程,android开发flex4.5入门教程.pdf

    android开发flex4.5入门教程 中国矿业大学教务部 教务通知(2013 )第33 号 关于做好各级"大学生创新训练计划" 项目中期检查和结题验收的通知 各学院: 为加强我 ...

  5. 2020最新android教程,Android教程2020

    本文介绍RecyclerView设置点击的方法.这里给出比较常见的使用方式. 用户点击某个item时,app可以做出相应的反应.这里我们使用添加点击监听器的方式来实现这个效果. Android开发中, ...

  6. orbot android教程,Android Orbot malformed reply from SOCKS server

    问题 I am trying to enable TOR support on my own XMPP app in android. I am using orbot as TOR proxy an ...

  7. monkey android 教程,Android Monkey使用详解

    Monkey 是Android SDK提供的一个命令行工具,是一个黑盒压力测试工具,采用随机算法,对被测应用随机发送伪随机的用户事件流,如点击,拖拽,滑动,输入等,来确定应用是否会发生异常,并且会产生 ...

  8. skia android 教程,Android下Skia遮罩特效的实现

    大体需求是,有一个文字点阵,叫glyph,为单色点阵,有笔画的地方为黑色,1:无笔画的地方为白色,0: 现在要把这个字画到屏幕,还有一个要求,要用当前颜色画: 分析来分析去,这就是一个简单的rop3操 ...

  9. paypal创建订单后怎么获得id_新支付无国界:PayPal注册教程

    上篇文章叙述了如何创建服务器,其中提到了利用PayPal支付,今天我们就来说一下PayPal注册教程. 什么是PayPal PayPal是当前全世界最大的在线支付工具,它的功能就像国内的支付宝一样,是 ...

  10. 详细教程: android项目集成PayPal 支付

    2017年7月5日  更新了, 总体该说的都说了, 后面再看看还有啥细节补充吧. 项目是跨境电商,国外的支付需要集成paypal支付,在网上搜了好久,教程都是断断续续,对开发者来说不太友好! 好在现在 ...

最新文章

  1. 什么是 CAS 机制?
  2. 浪潮as5300技术方案_混闪存储AS5300G5
  3. parted如何将磁盘所有空间格式化_linux下大于2T的硬盘格式化方法
  4. 鸟哥的 Linux 私房菜7 -- 首次开机关机与基本指令执行
  5. db2 存储过程异常处理
  6. IPV6 Socket编程
  7. 应用程序偏好设置(转)
  8. linux 下 docker NGINX+PHP+MYSQL+REDIS+Elasticsearch 开发环境搭建
  9. Oracle的expdp导出、impdp导出命令
  10. informix数据库维护常用命令
  11. iText API操作doc文档
  12. Codeforces Round #701 D. Multiples and Power Differences LCM性质
  13. [360] 《如何保持电力接触网与受电弓亲密接触》
  14. 不要过分相信基础函数, 因为那也是人写的------警惕负负得正的现有逻辑之坑
  15. 投资中的N种认知偏差总有一款败你
  16. 宏碁暗影骑士AN515-55/57/58原厂预装系统oem镜像
  17. 关于Unicode字符集,将char数组转化成LPCTSTR
  18. 怎么知道本台计算机的用户名和密码,访问其它电脑时“开始-运行-\输入要连接的电脑的IP,用户名和密码输入什么?...
  19. WordBias | 可视化文本中的偏见(刻板印象)
  20. c#窗体应用计算机设计,C#应用程序设计

热门文章

  1. 计算机房精密空调术语,机房空调常用单位及计算公式
  2. 常见电子元器件的极性识别方法
  3. Ubuntu20.04更换阿里源教程
  4. 【人月神话】浅谈人月神话0.2什么是“人月”,为什么是“神话”?
  5. Coablt strike官方教程中文译版本
  6. python+django+mysql图片分享平台毕业设计毕设开题报告
  7. matlab表示dbm,[转载]dBm换算成mW
  8. window10运行不了1stopt_1stopt win10版下载
  9. APP测试与WEB测试
  10. PAT-Basic Level-1001 害死人不偿命的(3n+1)猜想;