@ bunceapp/ react-native-paypal (英语)
反应原生包装机 连接PayPal iOS和Android SDK,
仅支持 requestBillingAgreement 现在
平台兼容性
| Android 设备 | Android 模拟器 | iOS 设备 | iOS 模拟器 | 博览会 | 网页 |
|---|---|---|---|---|---|
| ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
文档
API 参考。 。 。 .
从0.8.x升级? 1.0.0 移动到 Braintree Android v5 和 iOS v7 和 是一个破解的释放。 见 移徙指南。 。 。 .
安装
yarn add @bounceapp/react-native-paypal
这个 博览模块,所以你的应用程序
需求 expo 软件包。 裸体反应原生应用程序可以添加
npx install-expo-modules@latest它需要博览会SDK 56或以后.
所需资源
| 最低 | |
|---|---|
| 博览 | SDK 56 (英语) |
| iOS系统 | 16.0 (Braintree iOS v7) (英语) |
| 机器人 | API 23 (Braintree Android v5) (英语) |
Android 返回 URL 软件
Braintree Android v5 从 PayPal 流出返回 Android 应用程序
链接,所以你需要一个域
您控制服务 assetlinks.json 上面列出了你的应用程序。 传出此 URL 为
appLinkReturnUrl 每页 requestBillingAgreement 电话.
给 App 链接自己的路径, 例如 /paypal,并涵盖意图过滤器
用一个 pathPrefix。没有一条,过滤器就声称
主机,所以如果你使用您的主要域名,它的所有网络链接都会打开您的应用程序.
关于Braintree如何处理回归的两件事:
- 这个
pathPrefix只有Android发送到您的应用程序的瞄准镜。 脑树 本身与单机和主机的返回匹配,所以同一上的另一个链接 在流中到达应用程序的主机不是 PayPal 返回 。 它解决为Canceled。 。 。 . - 如果App Link没有被验证,Braintree就会倒回
${applicationId}.braintree计划本身.
这个 ${applicationId}.braintree 方案仍然被使用,现在作为
已经关闭“开放支持链接”的购买者。 这个图书馆来源于
您的应用程序 ID 自动 - 您只需要继续声明.
零工流量
// android/app/src/main/AndroidManifest.xml
<activity
android:name=".MainActivity"
// ...
>
// ...
<!-- App Link: the primary return path. -->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="https"
android:host="your-app.example.com"
android:pathPrefix="/paypal" />
</intent-filter>
<!-- Deep link: the fallback return path. -->
<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>
博览
以您通过的相同 URL 添加配置插件 appLinkReturnUrl数字 :
// app.json
{
"expo": {
"plugins": [
[
"@bounceapp/react-native-paypal",
{ "appLinkReturnUrl": "https://your-app.example.com/paypal" }
]
]
}
}
在预建时,它将两个意图过滤器添加到你的主要活动: App Link,
以一个 pathPrefix,则 .braintree 倒计时
计划,来源于 android.package 恰好是图书馆在
运行时间。 如果你宣称自己过滤到下面
expo.android.intentFilters,删除它.
用法实例
// App.tsx
import { useState } from "react"
import { Button } from "react-native"
import { requestBillingAgreement } from "@bounceapp/react-native-paypal"
export default function App() {
const [loading, setLoading] = useState(false)
const onPress = async () => {
setLoading(true)
const res = await requestBillingAgreement({
clientToken: "CLIENT_TOKEN",
// Android only: your verified App Link. Ignored on iOS.
appLinkReturnUrl: "https://your-app.example.com/paypal",
})
setLoading(false)
if (res.error) {
console.error(res.error)
return
}
}
return <Button title="Pay with PayPal" onPress={onPress} disabled={loading} />
}
每个预期成果都决定: payload,或一个 error 谁
code 实值 Canceled 或者说 Failed。承诺只拒绝编程
错误, 如错误类型的选项, 因此不需要
try编号 :catch 绕着呼叫正常使用.
捐款
见 贡献指南 学习如何为储存库和发展工作流程作出贡献.
许可证
源代码载于 麻省理工学院许可证。一些依赖性可以使用不同的许可证,例如BSD许可证.