Android集成Paypal支付Braintree

article/2025/8/22 22:13:01

最新发现Paypal的官方SDK已经不再维护了,所以需要把项目的支付做一下升级。

文档链接:点击这里

根据文档来看Paypal支付的集成相比以前简单了许多,下面我们讲一下集成步骤:

1:在 build.gradle 中添加以下内容

    compile 'com.braintreepayments.api:braintree:2.+'

2:在你的 AndroidManifest.xml  中添加

<activity android:name="com.braintreepayments.api.BraintreeBrowserSwitchActivity"android:launchMode="singleTask"><intent-filter><action android:name="android.intent.action.VIEW" /><category android:name="android.intent.category.DEFAULT" /><category android:name="android.intent.category.BROWSABLE" /><data android:scheme="${applicationId}.braintree" /></intent-filter>
</activity>

3:从服务器获取Token

     根据后台提供的 url 获取到Token  后台 集成链接

 

4:初始化

@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_paypal);  
//初始化并添加监听try {mBraintreeFragment = BraintreeFragment.newInstance(this, mAuthorization);mBraintreeFragment.addListener(new ConfigurationListener() {@Overridepublic void onConfigurationFetched(Configuration configuration) {}});// 支付完成监听mBraintreeFragment.addListener(new PaymentMethodNonceCreatedListener() {@Overridepublic void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {// Send nonce to serverString nonce = paymentMethodNonce.getNonce();postNonceToServer(nonce);if (paymentMethodNonce instanceof PayPalAccountNonce) {PayPalAccountNonce payPalAccountNonce = (PayPalAccountNonce) paymentMethodNonce;// Access additional informationString email = payPalAccountNonce.getEmail();String firstName = payPalAccountNonce.getFirstName();String lastName = payPalAccountNonce.getLastName();String phone = payPalAccountNonce.getPhone();// See PostalAddress.java for detailsPostalAddress billingAddress = payPalAccountNonce.getBillingAddress();PostalAddress shippingAddress = payPalAccountNonce.getShippingAddress();}}});// 取消监听mBraintreeFragment.addListener(new BraintreeCancelListener() {@Overridepublic void onCancel(int requestCode) {}});// 错误监听mBraintreeFragment.addListener(new BraintreeErrorListener() {@Overridepublic void onError(Exception error) {if (error instanceof ErrorWithResponse) {ErrorWithResponse errorWithResponse = (ErrorWithResponse) error;BraintreeError cardErrors = errorWithResponse.errorFor("creditCard");if (cardErrors != null) {// There is an issue with the credit card.BraintreeError expirationMonthError = cardErrors.errorFor("expirationMonth");if (expirationMonthError != null) {// There is an issue with the expiration month.LogUtils.e("paypal",expirationMonthError.getMessage());}}}}});// mBraintreeFragment is ready to use!
} catch (InvalidArgumentException e) {// There was an issue with your authorization string.
}
}

5:调起支付

yourButton.setOnClickListener(new View.OnClickListener(){@Override public void onClick (View view){setupBraintreeAndStartExpressCheckout();
}
})
public void setupBraintreeAndStartExpressCheckout() {PayPalRequest request = new PayPalRequest(“价格”).currencyCode("货币符号").intent(PayPalRequest.INTENT_SALE);PayPal.requestOneTimePayment(mBraintreeFragment, request);
}

这里注意三种Intent的意思  INTENT_SALE 表示立即到账。

5:付款成功后访问服务器验证

private void postNonceToServer(String nonce) {final Map<String, String> dataMap = new HashMap<>();dataMap.put("nonce", nonce);dataMap.put("amount", price);}

 

验证的接口由后台给这里逻辑由后台处理,这里返回成功,说明支付并验证成功。

 

大家测试的时候一定要用美国地址的paypal进行测试哈。

 

 


http://chatgpt.dhexx.cn/article/ynPh9DvJ.shtml

相关文章

:braintree_Laravel和Braintree:中间件和其他高级概念

:braintree This article was peer reviewed by Viraj Khatavkar. Thanks to all of SitePoint’s peer reviewers for making SitePoint content the best it can be! 本文由Viraj Khatavkar进行了同行评审。 感谢所有SitePoint的同行评审人员使SitePoint内容达到最佳状态&…

braintree_Laravel和Braintree,坐在树上……

braintree This article was peer reviewed by Younes Rafie and Wern Ancheta. Thanks to all of SitePoint’s peer reviewers for making SitePoint content the best it can be! 这篇文章由Younes Rafie和Wern Ancheta进行了同行评审。 感谢所有SitePoint的同行评审人员使S…

braintree使用_使用Braintree v.zero SDK购买时间

braintree使用 This article was sponsored by Braintree. Thank you for supporting the sponsors who make SitePoint possible! 本文由Braintree赞助。 感谢您支持使SitePoint成为可能的赞助商&#xff01; Braintree touts itself as offering “Simple, powerful payment…

简单聊聊PayPal与BrainTree选型经历

2019年9月30日&#xff0c;PayPal公司被批准通过对国付宝的股权收购正式进入中国。2019年12月19日晚间&#xff0c;PayPal公司正式宣布&#xff0c;已完成对国付宝信息科技有限公司&#xff08;Gopay&#xff09;70%的股权收购。交易完成后&#xff0c;PayPal成为第一家获准在中…

Braintree PayPal 支付网关开发(二)

开发准备在上篇文章已经介绍 >>看这里 << 这篇文章说下Demo示例。 1. 开发流程图这里再贴一下&#xff08;很重要&#xff09;&#xff1a; 2. 前端页面 2.1 代码 <div class"wrapper"><div class"checkout container"><…

braintree_Braintree的透明重定向

braintree The mere mention of “PCI Compliance” usually elicits a combination of confused looks and sweaty palms from business owners who accept credit card payments online. But what does it really mean? 仅仅提到“ PCI Compliance”通常会引起混淆的外观和来…

uniapp app端 对接 braintree

背景 项目客户端是uniapp&#xff08;app端&#xff09;&#xff0c;用户是海外微信支付宝肯定不行了&#xff0c;安卓苹果端都要&#xff0c;可选的支付方式有&#xff1a;1、苹果支付谷歌支付。2、paypal。3、Stripe 我比较看好paypal&#xff0c;最后领导决定用braintree。…

braintree支付开发整合paypal

braintree支付开发 braintree介绍 流程介绍 前端从服务端请求一个客户端令牌&#xff0c;并初始化客户端SDK。 服务端SDK生成客户端令牌并将其发送回客户端 客户提交付款信息&#xff0c;客户端SDK将该信息传递给Braintree&#xff0c;并返回付款方式随机数 前端付款方式随…

uniapp|vue 中的 braintree 支付

参考文档&#xff1a; Braintree-国外支付对接&#xff08;一&#xff09; Braintree-国外支付对接&#xff08;二&#xff09; Braintree-国外支付对接&#xff08;三&#xff09; 前面的两篇文章&#xff0c;有详细介绍了 Braintress 的账号创建&#xff1b;以及 SandBox 测…

Braintree PayPal 支付网关开发(一)

一般网上消费流程&#xff1a; 消费者 > 商户网站 > 消费者账户银行 > 支付网关 > 支付处理系统 > 商户收款银行 Braintree 就是一种支付方式。 Braintree 支付网关开发的准备&#xff1a; Braintree 支付网关开发流程&#xff1a; 第1步&#xff1a;前端请求自…

Braintree-国外支付对接(二)

在前文 国外支付对接&#xff1a;Braintree&#xff08;一&#xff09;的基础上 已经拿到了相关配置信息&#xff0c;接下来就是码代码了&#xff0c;这里完成的主要功能是支付与退款。 在此之前&#xff0c;先说一下Briantree的支付流程&#xff1a; 第一步先生成clientToke…

app接入 Paypal BrainTree

BrainTree 是什么 braintree 一开始是一个独立支付网关&#xff08;gateway&#xff09;&#xff0c;后来在2013年左右&#xff08;没记错的话&#xff09;被 Paypal收购。收购之后基本可以看作与paypal是一家。 paypal 收购 braintree 之后 sdk 也转向重点接入 braintree&…

多种方式99.9%解决从PDF复制文字后乱码问题

背景 需要从PDF复制文字出来做笔记&#xff0c;可是谁知道PDF通过adobe打开后复制出来后是乱码&#xff0c;如下图所示&#xff1a; &#xff08;再次感谢guide哥整理的文档&#xff09; 解决 尝试过安装字体&#xff0c;可惜没卵用。 方法1-CAJViewer打开 用该软件打开后…

java word转pdf 在linux转pdf乱码解决方法

word转pdf word转pdf,完美转换 引入依赖 (maven仓库是没有的&#xff0c;需要在项目中引用) 链接: 下载地址. 然后在pom里面引入下面这段&#xff0c;依赖我们就搭建好了 <dependency><groupId>com.aspose</groupId><artifactId>aspose-words</a…

word转pdf公式乱码_MathType转换成pdf符号丢失或乱码怎么办

一般写论文的时候是在Word中编写&#xff0c;在Word中写公式时一般是使用MathType&#xff0c;MathType编辑出来的公式非常标准与美观&#xff0c;很多国际期刊杂志都有这种要求。但是在将编写好的论文进行投稿时需要将Word文档转换成PDF文档&#xff0c;这样论文公式才不会发生…

itextpdf生成pdf中文乱码 (乱码中挣扎的自述)

生成pdf文件的方法有很多&#xff0c;网上也有很多的介绍&#xff0c;本文主要主要是讲生成pdf乱码的问题&#xff0c;而且还十分诡异&#xff0c;具体生成pdf的步骤同学们可以自己百度&#xff0c;也可以参考如下链接&#xff1a; https://www.cnblogs.com/LUA123/p/5108007.…

pdf转换html乱码怎么办,pdf转word后乱码怎么办?

pdf转word后乱码怎么办&#xff1f;网络上面有一些PDF资料你可以对其内容复制&#xff0c;但是粘贴到word或者文本中就是一堆乱码&#xff0c;你用转换软件转换出来&#xff0c;有一些文件不会是乱码&#xff0c;但是还有一些文件依旧是乱码&#xff0c;怎么办呢&#xff1f;今…

表格生成pdf 中字乱码

表格生成pdf及解决中字乱码 npm库表格生成pdf的超简洁小例子(用的是npm导入字体)两种解决乱码方法直接引入npm引入在项目中导入stsong-font在所需的页面上引用最后在生成pdf函数中使用(同上) npm库 两个必备包 jspdf npm i jspdfjspdf-autotable npm i jspdf-autotable在所需…

php生成pdf乱码_ierport 生成pdf出现乱码问题

iReport导出pdf中文乱码问题解决 使用iReport的过程经常遇到一些乱码的问题&#xff0c;最近用iReport导出pdf的时候就遇到中文不能显示的问题。 要使导出的pdf能够显示中文&#xff0c;需要用到iTextAsian.jar包。 1.将显示中文的地方Text属性设置成支持中文的字体。 Pdf font…

PDF文件复制文本为乱码

PDF文件可能会出现复制文本粘贴成乱码的现象。原因是PDF中所用的字体无法在电脑中找到&#xff0c;点击编辑器的”文件-属性“&#xff0c;查看字体&#xff0c;如果字体可以下载&#xff0c;可以在网上下载安装&#xff0c;就可以进行复制粘贴。 但有的PDF为保护内容&#xff…