如何将PayPal付款方式集成在iOS应用Swift 4中



我正在开发PayPal支付网关的应用程序。因此,我已经浏览了几个博客,但没有发现它有帮助。因此,如果有人可以提出一些非常有帮助的东西。

用于将PayPal付款集成到您的Swift IOS应用程序中,您需要使用Braintree SDK,该SDK提供了所有内置功能进行实施。

始终最好实现客户服务器架构以进行付款,在该付款中,服务器将具有业务逻辑,客户端将提供付款的接口。智能创建一个用于测试和开发目的的Sandbox帐户。

您可以从文档中了解实现的基本体系结构。文档中还提供了代码段,以简化集成过程。

  1. 概述和体系结构 - 这将提供有关结构和过程的基本信息

  2. 本API指南 - 实现客户端和服务器的总体指南。

  3. 下降UI-使用SDK付款UI

只有通过贝宝(PayPal API(和aswebauthenticationsessions(sfauthenticationsessionsession(,也有可能在没有Braintree的情况下整合PayPal(

1步:通过PayPal API创建订单例如&quot" https://mydomain/paypalpaymentredirect.html"(在PayPal API中的错误(,您必须将重定向配置为您在AswebauthentiCationSession中指定的URL方案(myApp://return_from_paypal(。

访问:https://developer.apple.com/documentation/xcode/allowing_apps_and_websites_to_to_link_to_your_your_your_your_content/defining_a_custom_url_url_url_url_scheme_scheme_for_your_your_your_app添加新的URL方案的信息,

https://developer.paypal.com/docs/api/orders/v2/#orders_create

样本请求:

curl -v -X POST https://api.sandbox.paypal.com/v2/checkout/orders 
-H "Content-Type: application/json" 
-H "Authorization: Bearer Access-Token" 
-d '{
  "intent": "CAPTURE",
  "purchase_units": [
    {
      "amount": {
        "currency_code": "USD",
        "value": "100.00"
      }
    }
  ],
  "order_application_context" : {
    "return_url" : "https://www.someDomain.de/redirectToMyAppScheme"
  }
}'

2步骤:成功创建订单后,PayPal API将返回批准URL,然后使用此URL启动AswebauthentiCationSessionsessessessessessessionSession,用户通过了PayPal流,您将获取pounterionhandler中的回调URL,如果成功,则将附加令牌和PAYERID附加。

codeSample:

webAuthSession = ASWebAuthenticationSession.init(url: URL(string: "https://www.paypal.com/checkoutnow?token=5O190127TN364715T") , callbackURLScheme: "myApp://return_from_paypal", completionHandler: { (callBack: URL?, error: Error?) in

3步:步骤2之后成功完成,您现在可以使用您在创建订单时收到的捕获URL成功完成PayPal的订单。https://developer.paypal.com/docs/api/orders/v2/#orders_capture

样本请求

curl -v -X POST https://api.sandbox.paypal.com/v2/checkout/orders/5O190127TN364715T/capture 
-H "Content-Type: application/json" 
-H "Authorization: Bearer Access-Token" 
-H "PayPal-Request-Id: 7b92603e-77ed-4896-8e78-5dea2050476a

"

最新更新