简体   繁体   English

REACT NATIVE 的 PayPal 支付集成与最新的 lib android + ios

[英]PayPal payment integration for REACT NATIVE with latest lib android + ios

Can any body provide a swipe solution with latest react-native PayPal library ?任何机构都可以提供带有最新react-native PayPal 库的刷卡解决方案吗?

I have spent a week but not getting a proper solution.我花了一个星期但没有得到一个合适的解决方案。

There are many old and incomplete solution on net but not a proper and complete solution for new developers.网络上有许多旧的和不完整的解决方案,但对于新开发人员来说,没有一个合适和完整的解决方案。

Resources :资源 :

https://www.npmjs.com/package/react-native-paypal https://www.npmjs.com/package/react-native-paypal

https://github.com/MattFoley/react-native-paypal https://github.com/MattFoley/react-native-paypal

https://github.com/sharafat/sample-code-php https://github.com/sharafat/sample-code-php

Unfortunately, there isn't a single repo that is up to date and maintains by the community as far as I know.不幸的是,据我所知,社区中没有一个是最新的并由社区维护的存储库。 That's why your options are limited.这就是您的选择有限的原因。

Utilize PayPal APIs使用 PayPal API

PayPal has various APIs for different use cases that you can pick up without worrying about the SDK itself. PayPal 为不同的用例提供了各种 API,您可以选择这些 API,而无需担心 SDK 本身。 They give you lots of those functionalities, sure it might not be smooth as the SDK itself, but it can solve your problem, nicely.它们为您提供了许多这些功能,当然它可能不像 SDK 本身那样流畅,但它可以很好地解决您的问题。

In case you are developing for both mobile and the web, you can use your APIs for both of them.如果您同时为移动设备和 Web 进行开发,则可以将您的 API 用于两者。 Becuase they do not depend on the specific platform.因为它们不依赖于特定的平台。

Solution解决方案

My solution for this is pretty straightforward.我对此的解决方案非常简单。 Do not use the PayPal SDK if you don't want to mess with Native functionality and not exactly sure why you need it.如果您不想弄乱本机功能并且不确定为什么需要它,请不要使用 PayPal SDK。 PayPal has a various set of APIs that you can use on your server side or client side without touching the native code. PayPal 有一组不同的 API,您可以在服务器端或客户端使用这些 API,而无需接触本机代码。 Here I give you a simple scenario that using ExpressCheckout APIs and handle on the server side.这里我给你一个简单的场景,使用 ExpressCheckout APIs 并在服务器端处理。

For all below steps, you can use PHP, Node or any other server-side languages.对于以下所有步骤,您可以使用 PHP、Node 或任何其他服务器端语言。 I only briefly tell you the steps and the rest are on you!我只简单的告诉你步骤,剩下的就靠你了!

1. Create an access token for your transaction. 1. 为您的交易创建访问令牌。 Follow below link for details.请按以下链接了解详情。

https://developer.paypal.com/docs/integration/direct/make-your-first-call https://developer.paypal.com/docs/integration/direct/make-your-first-call

2. Create a payment transaction. 2. 创建支付交易。 You need to pass your payment details such as currency and total amount.您需要传递您的付款详细信息,例如货币和总金额。 In this step, you can pass your 'return_url' and cancel_url too.在这一步中,您也可以传递您的 'return_url' 和 cancel_url。 Make sure to attach your order id or order code to both of them, so you can track the orders when either of them triggered and change your order status accordingly.确保将您的订单 ID 或订单代码附加到它们两个上,以便您可以在其中任何一个触发时跟踪订单并相应地更改您的订单状态。

https://developer.paypal.com/docs/integration/direct/express-checkout/integration-jsv4/advanced-payments-api/create-express-checkout-payments/ https://developer.paypal.com/docs/integration/direct/express-checkout/integration-jsv4/advanced-payments-api/create-express-checkout-payments/

3. Send the payment URL to React Native and load it by WebView. 3. 将支付 URL 发送到 React Native 并通过 WebView 加载。 In this Step, you can use the WebView component in React Native and load the PayPal URL inside.这一步可以使用 React Native 中的 WebView 组件,加载里面的 PayPal URL。 Later for checking whether the payment is done, you can either use a throttling function or use other alternatives such as WebSocket.稍后检查付款是否完成,您可以使用限制功能或使用其他替代方案,例如 WebSocket。 The goal here is to know whether the transaction is done or canceled.这里的目标是知道交易是完成还是取消。

When the payment is done.付款完成后。 get rid of the WebView and redirect the user to thank you page and any other things you need to do after the user payment is done.摆脱 WebView 并将用户重定向到感谢页面以及在用户付款完成后您需要做的任何其他事情。

There might be more elegant ways to do this, but I believe for simple scenarios (or even more!) this is sufficient.可能有更优雅的方法来做到这一点,但我相信对于简单的场景(甚至更多!)这已经足够了。

As Danial suggested above, if you do not want your app do be dependant on third party react native libraries then try integrating paypal with a WebView wrapper.正如上面建议的那样,如果您不希望您的应用程序依赖第三方反应本机库,请尝试将 paypal 与 WebView 包装器集成。 Here is how I did it Integrating Paypal in your react native app这是我在你的本机应用程序中集成 Paypal 的方法

附截图链接= https://www.npmjs.com/package/react-native-paypal-lib将此库用于React Native Application 实现非常简单,请按照以下步骤进行实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM