【问题标题】:How to integrate Paypal Payment Method in iOS App Swift 4?如何在 iOS App Swift 4 中集成 Paypal 付款方式?
【发布时间】:2019-12-10 21:30:11
【问题描述】:

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

【问题讨论】:

    标签: ios swift paypal swift4


    【解决方案1】:

    要将 Paypal 支付集成到您的 swift ios 应用程序中,您需要使用 Braintree SDK,它提供了所有内置功能以供实施。

    为支付实现客户端-服务器架构总是更好,其中服务器将具有业务逻辑,客户端将提供支付接口。请创建一个沙箱帐户用于测试和开发目的。

    您可以从文档中了解实现的基本架构。文档中还提供了代码 sn-ps 以简化集成过程。

    1. Overview and architecture - 这将提供有关结构和过程的基本信息

    2. This the api guide - 实现客户端和服务器的总体指南。

    3. Drop in UI - 使用 SDK 的支付界面

    【讨论】:

    【解决方案2】:

    也可以在没有 Braintree 的情况下集成 PayPal,仅通过 PayPal API 和 ASWebAuthenticationSession (SFAuthenticationSession)

    1 步骤: 通过 PayPal API 创建订单,在 application_context 对象中 return_url 必须指向 http/https: 域例如“https://mydomain/paypalpaymentredirect.html”(PayPal API 中的错误),您必须配置重定向到您在 ASWebAuthenticationSession (myApp://return_from_paypal) 中指定的 url 方案。

    访问:https://developer.apple.com/documentation/xcode/allowing_apps_and_websites_to_link_to_your_content/defining_a_custom_url_scheme_for_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 将启动 ASWebAuthenticationSession,在用户通过 PayPal 流程后,您将在completionHandler中获取callBack URL,成功时会附加token和PayerID。

    代码示例:

    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
    

    "

    【讨论】:

    • 嗨,我正在尝试使用这些方法进行连接,但它没有返回到我的应用程序中是否有任何更新。
    • 您好,我的应用程序中有此配置,仍在工作。您是否用自己的域替换了返回 URL 并在那里配置了重定向到您的应用程序 URL 方案?在 Xcode 中,您必须在 Project -> you main target -> Info 下配置 URL Scheme。在那里,您可以在 URL 类型下添加方案。
    猜你喜欢
    • 2018-08-17
    • 2016-04-06
    • 2016-05-23
    • 1970-01-01
    • 2017-10-23
    • 2011-03-07
    • 2012-10-22
    • 2014-07-30
    • 2017-02-19
    相关资源
    最近更新 更多