How to integrate Paypal Payment Method in iOS App Swift 4?

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-20 05:14:07

问题


I'm working on an app in which PayPal payment gateway is to integrate. As such I have gone through several blog but did not found it helpful. So if any can suggest something that would be very helpful.


回答1:


For integrating Paypal payment into your swift ios application, you would need to use Braintree SDK which provides all the inbuilt functions for implementation.

Its always better to implement client-server architecture for payment where the server would have the business logic and client would provide an interface for payment.Kindly create a sandbox account for testing and development purpose.

You can learn about the basic architecture of implementation from the documentation.Code snippets are also provided in the documentation to ease the integration process.

  1. Overview and architecture - this would provide basic information about the structure and process

  2. This the api guide - overall guide to implement client and server.

  3. Drop in UI - Payment UI using SDK



回答2:


There is also the possibility to integrate PayPal without Braintree, only via the PayPal API and ASWebAuthenticationSession (SFAuthenticationSession)

1 Step: Create an order via the PayPal API, in the application_context object the return_url must point to a http/https: domain for example "https://mydomain/paypalpaymentredirect.html" (bug in the PayPal API), there you have to configure the redirect to the url scheme you specified in the ASWebAuthenticationSession (myApp://return_from_paypal).

Visit: https://developer.apple.com/documentation/xcode/allowing_apps_and_websites_to_link_to_your_content/defining_a_custom_url_scheme_for_your_app for more Information of how to add a new URL scheme to your App.

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

Sample Request:

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 Step: after the successful creation of the order the PayPal API will return the approve URL to you, with this URL the ASWebAuthenticationSession will be started, after the user has passed the PayPal flow you will get the callBack URL in the completionHandler, in case of success the token and the PayerID will be attached.

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 Step: after step 2 has been completed successfully, you can now successfully complete the order at PayPal using the capture URL that you received when creating the order. https://developer.paypal.com/docs/api/orders/v2/#orders_capture

Sample Request

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

"



来源:https://stackoverflow.com/questions/57323334/how-to-integrate-paypal-payment-method-in-ios-app-swift-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!