{"id":18989461,"url":"https://github.com/thiendangit/react-native-paypal-swift","last_synced_at":"2025-04-22T11:09:28.682Z","repository":{"id":57339032,"uuid":"380806948","full_name":"thiendangit/react-native-paypal-swift","owner":"thiendangit","description":"React Native library that implements PayPal Checkout flow using purely native code (swift).","archived":false,"fork":false,"pushed_at":"2021-07-03T12:50:21.000Z","size":370,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-16T22:09:15.978Z","etag":null,"topics":["native-module","paypal","react-native","swift","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/react-native-paypal-swift","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thiendangit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-27T18:03:44.000Z","updated_at":"2024-05-06T04:45:56.000Z","dependencies_parsed_at":"2022-08-28T10:00:36.079Z","dependency_job_id":null,"html_url":"https://github.com/thiendangit/react-native-paypal-swift","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiendangit%2Freact-native-paypal-swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiendangit%2Freact-native-paypal-swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiendangit%2Freact-native-paypal-swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiendangit%2Freact-native-paypal-swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thiendangit","download_url":"https://codeload.github.com/thiendangit/react-native-paypal-swift/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249745815,"owners_count":21319581,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["native-module","paypal","react-native","swift","typescript"],"created_at":"2024-11-08T17:06:44.841Z","updated_at":"2025-04-22T11:09:28.661Z","avatar_url":"https://github.com/thiendangit.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-native-paypal-swift\n\nReact Native library that implements PayPal [Checkout](https://developers.braintreepayments.com/guides/paypal/checkout-with-paypal/) flow using purely native code (swift).\n\n\u003cimg src=\"images/screenshot.png\" alt=\"React Native library\" width=\"350\"/\u003e\n\n## Installation\n\n```sh\nnpm install react-native-paypal-swift or `yarn add react-native-paypal-swift`\n```\n\n1. [iOS] Add `pod 'Braintree', '~\u003e 4'` and `pod 'Braintree/DataCollector'` to your Podfile.\n1. [iOS] Run `pod install`\n1. [iOS] Register a URL scheme in Xcode (**must** always start with your Bundle Identifier and end in `.payments` - e.g. `your.app.id.payments`). See details [here](https://developers.braintreepayments.com/guides/paypal/client-side/ios/v4#register-a-url-type).\n1. [iOS] Edit your `AppDelegate` as follows:\n\n   Objective C ~\u003e AppDelegate.m\n    ```objc\n    #import \"BraintreeCore.h\"\n    #import \"BraintreePayPal.h\"\n    #import \"BTDataCollector.h\"\n\n    static NSString *URLScheme;\n\n    @implementation AppDelegate\n\n    - (BOOL)application:(UIApplication *)application\n      didFinishLaunchingWithOptions:(NSDictionary *)launchOptions\n    {\n      NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];\n      NSString *urlscheme = [NSString stringWithFormat:@\"%@.payments\", bundleIdentifier];\n      URLScheme = urlscheme;\n      [BTAppSwitch setReturnURLScheme:urlscheme];\n    }\n\n    // if you support only iOS 9+, add the following method\n    - (BOOL)application:(UIApplication *)application\n        openURL:(NSURL *)url\n        sourceApplication:(NSString *)sourceApplication\n        annotation:(id)annotation\n    {\n        if ([url.scheme localizedCaseInsensitiveCompare:URLScheme] == NSOrderedSame) {\n            return [BTAppSwitch handleOpenURL:url sourceApplication:sourceApplication];\n        }\n        return NO;\n    }\n\n    // otherwise, if you support iOS 8, add the following method\n      - (BOOL)application:(UIApplication *)application\n          openURL:(NSURL *)url\n          options:(NSDictionary\u003cUIApplicationOpenURLOptionsKey,id\u003e *)options\n      {\n          if ([url.scheme localizedCaseInsensitiveCompare:URLScheme] == NSOrderedSame) {\n              return [BTAppSwitch handleOpenURL:url options:options];\n          }\n          return NO;\n      }\n    ```\n\n     Swift ~\u003e AppDelegate.swift\n\n     ```swift\n        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -\u003e Bool {\n            BTAppSwitch.setReturnURLScheme(\"com.your-company.your-app.payments\")\n            return true\n        }\n\n       // if you're using UISceneDelegate (introduced in iOS 13), call BTAppSwitch's handleOpenURLContext method from within the scene:openURLContexts scene delegate method.\n        func scene(_ scene: UIScene, openURLContexts URLContexts: Set\u003cUIOpenURLContext\u003e) {\n            URLContexts.forEach { context in\n                if context.url.scheme?.localizedCaseInsensitiveCompare(\"com.your-company.your-app.payments\") == .orderedSame {\n                    BTAppSwitch.handleOpenURLContext(context)\n                }\n            }\n        }\n\n      // otherwise, if you aren't using UISceneDelegate, call BTAppSwitch's handleOpenURL method from within the application:openURL:options app delegate method.\n       func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -\u003e Bool {\n           if url.scheme?.localizedCaseInsensitiveCompare(\"com.your-company.your-app.payments\") == .orderedSame {\n               return BTAppSwitch.handleOpen(url, options: options)\n           }\n           return false\n       }\n    ```\n\n## Usage\n\nFirst you need to get a valid token from your server. Refer to [this](https://developers.braintreepayments.com/start/hello-client/ios/v3#get-a-client-token).\n\nThen you can execute the following code, for example reacting to a button press.\n\n\n```js\n    import {Paypal} from \"react-native-paypal-swift\";\n\n    // ...\n    const CLIENT_TOKEN = useMemo\u003cstring\u003e(() =\u003e 'sandbox_v29bk2j6_xxxxxxxxx', []);\n    // For one time payments\n   const requestOneTimePayment = useCallback(() =\u003e {\n       Paypal.requestOneTimePayment(CLIENT_TOKEN,\n         {\n           amount: '10',\n         },\n       ).then(resOneTimePayment =\u003e {\n            //   nonce,\n            //   payerId,\n            //   email ,\n            //   firstName,\n            //   lastName ,\n            //   phone,\n            //   billingAddress,\n            //   shippingAddress\n         console.log({ resOneTimePayment });\n       }).catch(err =\u003e {\n         console.log(err);\n       });\n     }, []);\n\n     const requestBillingAgreement = useCallback(() =\u003e {\n       Paypal.requestBillingAgreement(CLIENT_TOKEN,\n         {\n           billingAgreementDescription: 'Your agreement description',\n           currencyCode: 'GBP',\n           localeCode: 'en_GB',\n         },\n       ).then(resBillingAgreement =\u003e {\n            //   nonce,\n            //   payerId,\n            //   email ,\n            //   firstName,\n            //   lastName ,\n            //   phone,\n            //   billingAddress,\n            //   shippingAddress\n         console.log({ resBillingAgreement });\n       }).catch(err =\u003e {\n         console.log(err);\n       });\n     }, []);\n\n    const requestDeviceData = useCallback(() =\u003e {\n        Paypal.requestDeviceData(CLIENT_TOKEN).then(resDeviceData =\u003e {\n          alert(`Your correlation id: ${resDeviceData?.deviceData?.correlation_id}`);\n          console.log({ resDeviceData });\n        }).catch(err =\u003e {\n          console.log(err);\n        });\n      }, []);\n// ...\n```\n\n## Creating/Finding client token\nNote that the client token should be served via a backend service but can be hardcoded:\n1. Go to https://www.braintreegateway.com or https://sandbox.braintreegateway.com/ and login or create an account\n2. Click the gear at the top and select to API\n3. You can find your token under `Tokenization Keys`.  You will need to create one if none exists\n\n## Backend implementation\nFor an overview of the braintree payment flow see https://developers.braintreepayments.com/start/overview\n\nThis library covers the client setup here: https://developers.braintreepayments.com/start/hello-client\n\nIt does NOT however cover the server portion here: https://developers.braintreepayments.com/start/hello-server\n\nYou will need the server portion in order to complete your transactions.  See a simple example of this server in /exampleServer.  The example app is pointed to this on default\n\n\n## Contributing\n\nSee the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthiendangit%2Freact-native-paypal-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthiendangit%2Freact-native-paypal-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthiendangit%2Freact-native-paypal-swift/lists"}