Paypal PayFast
Follow this guide to add PayPal PayFast to your checkout.
- PAYPAL_PAYFAST - PayPal PayFast
Payment methods availability:
- PayPal PayFast since mSDK version 7.9.0
Configuration
To integrate PAYPAL_PAYFAST you need to add the Braintree dependencies in your project. Please download the XCFrameforks and add the dependencies following steps below:
- Download and unzip Braintree framework from Github.
- Download and unzip PPRiskMagnes framework from Braintree Assets.
- Drag and drop
BraintreeCore.xcframeworkto the "Frameworks" folder of your project.
Make sure "Copy items if needed" is checked. - Drag and drop
BraintreeDataCollector.xcframeworkto the "Frameworks" folder of your project.
Make sure "Copy items if needed" is checked. - Drag and drop
BraintreePayPal.xcframeworkto the "Frameworks" folder of your project.
Make sure "Copy items if needed" is checked. - Drag and drop
PPRiskMagnes.xcframeworkto the "Frameworks" folder of your project.
Make sure "Copy items if needed" is checked. - Check "Frameworks, Libraries, and Embedded Content" section under the general settings tab of your application's target. Ensure the Embed dropdown has Embed and Sign selected for the framework.
App Switch
App Switch enables buyers with the PayPal app installed to start checkout in a merchant app or website and seamlessly complete the flow in the PayPal app. This provides a low-friction authentication experience using native PayPal app login methods such as Face ID, biometrics, or passkeys.
Follow below given steps to set up switch flow:
- Refer this document to register your app for universal link. Your apple-app-site-association file should look like:
{ "applinks": { "details": [{ "appID": "TEAM_ID.BUNDLE_ID", "paths": ["/braintree-payments/*"] }] } } - Refer this link to register your app for on Braintree control panel.
- To allow your app to detect and switch to the PayPal app, add the PayPal URL scheme to the LSApplicationQueriesSchemes allowlist in your app’s Info.plist:
<key>LSApplicationQueriesSchemes</key> <array> <string>paypal</string> </array> - Add NSLocationWhenInUseUsageDescription key to your Info.plist with a description of why you are requesting location permission. This is required to use PayPal PayFast flow.
-
To handle universal link callback add below given method to your UISceneDelegate class.
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) { let success = OPPBraintreeProcessor.handleRedirection(userActivity) } func scene(_ scene: UIScene, openURLContexts URLContexts: Set) { URLContexts.forEach { context in if context.url.scheme?.localizedCaseInsensitiveCompare("your_app_scheme") == .orderedSame { OPPBraintreeProcessor.handleRedirection(url: context.url) } } } - (void)scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)userActivity { BOOL success = [OPPBraintreeProcessor handleRedirection:userActivity]; } - (void)scene:(UIScene *)scene openURLContexts:(NSSet*)URLContexts { for (UIOpenURLContext *context in URLContexts) { if ([context.URL.scheme caseInsensitiveCompare:@"your_app_scheme"] == NSOrderedSame) { BOOL success = [OPPBraintreeProcessor handleRedirectionWithUrl:context.URL]; } } }
Ready-to-Use UI
When you use our ready-to-use UI, everything works out-of-box. Just set PAYPAL_PAYFAST payment brand and set PayPal PayFast config in checkout settings class and you are done. Proceed with the presenting checkout as for standard transaction.
let checkoutSettings = OPPCheckoutSettings()
// Set PayPal PayFast payment brand
checkoutSettings.paymentBrands = ["PAYPAL_PAYFAST"]
let config = OPPBraintreeConfig.paypalPayFastConfig(universalLink:"https://yourdomain/braintree-payments",
URLScheme:"your_app_scheme"
enableAppSwitch:true)
checkoutSettings.setBrandConfig(config)
OPPCheckoutSettings *checkoutSettings = [[OPPCheckoutSettings alloc] init];
// Set PayPal PayFast payment brand
checkoutSettings.paymentBrands = @[@"PAYPAL_PAYFAST"];
OPPBraintreeConfig *config = OPPBraintreeConfig paypalPayFastConfigWithUniversalLink:@"https://yourdomain/braintree-payments"
URLScheme:@"your_app_scheme"
enableAppSwitch:YES];
[checkoutSettings setBrandConfig:config];
SDK & Your Own UI
In this guide we assume that you have already implemented all steps for performing standard mSDK transaction.
There are several steps that you have to perform to integrate PayPal PayFast, which are as follows:
1. Create PayPal PayFast brand configuration
Create PayPal PayFast brand configuration with universal link, url scheme and enable app switch parameters.
let config = OPPBraintreeConfig.paypalPayFastConfig(universalLink:"https://yourdomain/braintree-payments",
URLScheme:"your_app_scheme",
enableAppSwitch:true)
OPPBraintreeConfig *config = [OPPBraintreeConfig paypalPayFastConfigWithUniversalLink:@"https://yourdomain/braintree-payments"
URLScheme:@"your_app_scheme"
enableAppSwitch:YES];
2. Create PayPal PayFast payment param
Use checkoutId and config object created earlier to create PayPal PayFast Payment params.
do {
let parameter = try OPPBraintreePaymentParams.payPalPayFastPaymentParamsWith(checkoutId:checkoutId,
config:config)
} catch let error as NSError {
// Handle error
}
NSError *error;
OPPBraintreePaymentParams *parameter = [OPPBraintreePaymentParams payPalPayFastPaymentParamsWithCheckoutId:checkoutId
config:config
error:&error];
3. Create transaction object from payment params
You have to create transaction object.
let transaction = OPPTransaction(paymentParams: parameter)
OPPTransaction *transaction = [[OPPTransaction alloc] initWithPaymentParams:parameter];
4. Create Braintree processor object to process transaction
You have to create OPPBraintreeProcessor object and call process method on it to process the transaction.
let processor = try OPPBraintreeProcessor(transaction:transaction,
mode:mode)
processor.process { (transaction, error) in
if let error = error {
// Handle error
} else {
// Submit transaction
}
}
NSError *error;
OPPBraintreeProcessor *processor = [[OPPBraintreeProcessor alloc] initWithTransaction:transaction
mode:mode
error:&error];
if (error) {
// Handle error
} else {
[processor process:^(OPPTransaction * _Nonnull, NSError * _Nullable) {
if (error) {
// Handle error
} else {
// Submit transaction
}
}];
}
5. Submit transaction
Create a payment provider object and call submit transaction from completion handler of process function.
let provider = OPPPaymentProvider(mode:providerMode)
self.provider.submitTransaction(transaction, completionHandler: {(transaction, error) in
// Get payment status
})
OPPPaymentProvider *provider = [OPPPaymentProvider paymentProviderWithMode:providerMode];
[provider submitTransaction:transaction completionHandler:^(OPPTransaction * _Nonnull transaction, NSError * _Nullable error) {
// Get payment status
}];
6. Get the payment status
Finally your app should request the payment status from your server.
For more details you can refer to this document.
Configuration
Open the build.gradle file in the app module and add the following to the dependencies block
implementation 'com.braintreepayments.api:paypal:5.18.0'
implementation 'com.braintreepayments.api:data-collector:5.18.0'
App Switch
The App Switch will enable PayPal users who have a PayPal installed on their phone to complete payments on the PayPal app when it is available.
Follow below given steps to set up App Switch flow:
- Refer Android Developers docs to register your app for App link. Example of assetlinks.json file is shown below:
[{ "relation": ["delegate_permission/common.handle_all_urls"], "target": { "namespace": "android_app", "package_name": "com.example", // This should be the SHA256 fingerprints of your app's signing certificate. "sha256_cert_fingerprints": ["14:6D:E9:83:C5:73:06:50:D8:EE:B9:95:2F:34:FC:64:16:A0:83:42:E6:1D:BE:A8:8A:04:96:B2:3F:CF:44:E5"] } }] } - Refer this link to register your app link on Braintree control panel. Add your app link url without https:// in the braintree control panel.
- Add below code in your AndroidManifest.xml to get the result back in App switch flow:
<activity android:name="com.oppwa.mobile.connect.payment.processor.braintree.BraintreeProcessorActivity" android:exported="true"> <intent-filter android:autoVerify="true"> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="https"/> <data android:host="merchant-app.com"/> <!-- required if your app link contains a path --> <data android:pathPrefix="/path" /> </intent-filter /> </activity>
Ready-to-Use UI
1. Create Paypal Payfast Config
Create Paypal Payfast config and set it to brand configuration using CheckoutPaymentBrandConfig.Builder
PaypalPayfastConfig accepts the following parameters:
-
hasUserLocationConsent (Boolean, default: false)
Indicates whether your app has obtained user consent to collect location data, as required by Google Play policies. This allows PayPal to collect data for fraud detection and risk management. -
enableAppSwitch (Boolean, default: true)
Controls whether the App Switch flow is enabled. When set totrue, the transaction is processed through the PayPal app if it is installed on the user’s device; otherwise, it falls back to the web flow. If set tofalse, all transactions are processed via the web flow. -
appLinkReturnUrl (String)
The Android App Link URL associated with your app, used to return control to the app after completing the PayPal payment flow. If this is not correctly configured then the transaction will automatically fallback to web flow.
PaypalPayfastConfig paypalPayfastConfig = new PaypalPayfastConfig(false, true, "https://example.com");
CheckoutPaymentBrandConfig brandConfig = new CheckoutPaymentBrandConfig.Builder()
.setPaypalPayfastConfig(paypalPayfastConfig)
.build();
val paypalPayfastConfig = new PaypalPayfastConfig(false, true, "https://example.com");
val brandConfig = CheckoutPaymentBrandConfig.Builder()
.setPaypalPayfastConfig(paypalPayfastConfig)
.build()
2. Create CheckoutSettings
Create CheckoutSettings and set brand config
Set<String> paymentBrands = new LinkedHashSet<String>();
paymentBrands.add("PAYPAL_PAYFAST");
CheckoutSettings checkoutSettings = new CheckoutSettings(checkoutId, paymentBrands, Connect.ProviderMode.TEST);
checkoutSettings.setBrandConfig(brandConfig);
val paymentBrands = hashSetOf("PAYPAL_PAYFAST")
val checkoutSettings = CheckoutSettings(checkoutId, paymentBrands, Connect.ProviderMode.TEST)
checkoutSettings.setBrandConfig(brandConfig)
SDK & Your Own UI
In this guide we assume that you have already implemented all steps for performing standard mSDK transaction.
There are several steps that you have to perform to integrate PAYPAL_PAYFAST, which are as follows:
1. Create Paypal Payfast Config
Create Paypal Payfast config and set it to PaypalPayFastPaymentParams.
PaypalPayfastConfig accepts the following parameters:
-
hasUserLocationConsent (Boolean, default: false)
Indicates whether your app has obtained user consent to collect location data, as required by Google Play policies. This allows PayPal to collect data for fraud detection and risk management. -
enableAppSwitch (Boolean, default: true)
Controls whether the App Switch flow is enabled. When set totrue, the transaction is processed through the PayPal app if it is installed on the user’s device; otherwise, it falls back to the web flow. If set tofalse, all transactions are processed via the web flow. -
appLinkReturnUrl (String)
The Android App Link URL associated with your app, used to return control to the app after completing the PayPal payment flow. If this is not correctly configured then the transaction will automatically fallback to web flow.
PaypalPayfastConfig paypalPayfastConfig = new PaypalPayfastConfig(false, true, "https://example.com");
val paypalPayfastConfig = new PaypalPayfastConfig(false, true, "https://example.com");
2. Create Paypal Payfast payment params and transaction object
Use checkoutId, provider mode and brandConfiguration(paypalPayfastConfig) object created earlier to create PaypalPayfast Payment params.
PaypalPayFastPaymentParams paymentParams = new PaypalPayFastPaymentParams(checkoutId, Connect.ProviderMode.TEST, paypalPayfastConfig);
// no need to set ShopperResultUrl for PaypalPayfast
Transaction transaction = new Transaction(paymentParams);
val paymentParams = PaypalPayFastPaymentParams(checkoutId, Connect.ProviderMode.TEST, paypalPayfastConfig)
// no need to set ShopperResultUrl for PaypalPayfast
val transaction = Transaction(paymentParams)
3. Register ActivityResultLauncher object to launch Paypal Payfast launcher to initiate the transaction
To initiate PAYPAL_PAYFAST transaction you have to create ActivityResultLaucher object of PaypalPayfastProcessorResultContract and launch with the transaction object created in step 2.
4. Submit transaction
Create OppPaymentProvider object and call submit transaction by passing the transaction object received in Step 3. and the ITransactionListener callback parameter.
OppPaymentProvider paymentProvider = OppPaymentProvider(this, Connect.ProviderMode.TEST);
paymentProvider.submitTransaction(transaction, this);
val paymentProvider = OppPaymentProvider(this, Connect.ProviderMode.TEST)
paymentProvider.submitTransaction(transaction, this)
5. Get the payment status inside transactionCompleted() method of ITransactionListener.
Finally your app should request the payment status from your server.
For more details you can refer to this document.