Paypal Payfast
Follow this guide to add PayPal PayFast to your checkout.
- PAYPAL_PAYFAST - PayPal PayFast
Payment method 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.
- 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. - 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.
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 method
checkoutSettings.paymentBrands = ["PAYPAL_PAYFAST"]
let config = OPPBTPayPalPayFastConfig(universalLink:"https://yourdomain/braintree-payments",
URLScheme:"appurlscheme"
enableAppSwitch:true))
checkoutSettings.setBrandConfig(config)
OPPCheckoutSettings *checkoutSettings = [[OPPCheckoutSettings alloc] init];
// Set PayPal PayFast payment method
checkoutSettings.paymentBrands = @[@"PAYPAL_PAYFAST"];
OPPBTPayPalPayFastConfig *config = [[OPPBTPayPalPayFastConfig alloc] initWithUniversalLink:@"https://yourdomain/braintree-payments"
URLScheme:@"appurlscheme"
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 = OPPBTPayPalPayFastConfig(universalLink:"docs.oppwa.com",
URLScheme:"oppwa",
enableAppSwitch:true)
OPPBTPayPalPayFastConfig *config = [[OPPBTPayPalPayFastConfig alloc] initWithUniversalLink:@"docs.oppwa.com"
URLScheme:@"oppwa"
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 OPPBTPayPalPayFastPaymentParams.payPalPayFastPaymentParamsWith(checkoutId:checkoutId,
config:config)
} catch let error as NSError {
// Handle error
}
NSError *error;
OPPBTPayPalPayFastPaymentParams *parameter = [OPPBTPayPalPayFastPaymentParams 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 PayPal PayFast processor object to process transaction
You have to create PayPalPayFastProcessor object and call 'process' method on it to process the transaction.
let processor = try OPPBTPayPalPayFastProcessor(transaction:transaction,
mode:mode)
processor.process { (transaction, error) in
if let error = error {
// Handle error
} else {
// Submit transaction
}
}
NSError *error;
OPPBTPayPalPayFastProcessor *processor = [[OPPBTPayPalPayFastProcessor 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.
let provider = OPPPaymentProvider(mode:providerMode)
self.provider.submitTransaction(transaction, completionHandler: {(transaction, error) in
})
OPPPaymentProvider *provider = [OPPPaymentProvider paymentProviderWithMode:providerMode];
[provider submitTransaction:transaction completionHandler:^(OPPTransaction * _Nonnull transaction, NSError * _Nullable error) {
}];
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'
Ready-to-Use UI
1. Create Paypal Payfast Config
Create Paypal Payfast config and set it to brand configuration using CheckoutPaymentBrandConfig.Builder
PaypalPayfastConfig paypalPayfastConfig = new PaypalPayfastConfig(false, "docs.oppwa.com");
CheckoutPaymentBrandConfig brandConfig = new CheckoutPaymentBrandConfig.Builder()
.setPaypalPayfastConfig(paypalPayfastConfig)
.build();
val paypalPayfastConfig = new PaypalPayfastConfig(false, "docs.oppwa.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 brand configuration
Create Paypal Payfast brand configuration which takes hasUserLocationConsent and appLinkReturnUrl.
PaypalPayfastConfig paypalPayfastConfig = new PaypalPayfastConfig(false, "docs.oppwa.com");
CheckoutPaymentBrandConfig brandConfig = new CheckoutPaymentBrandConfig.Builder()
.setPaypalPayfastConfig(paypalPayfastConfig)
.build();
val paypalPayfastConfig = new PaypalPayfastConfig(false, "docs.oppwa.com");
val brandConfig = CheckoutPaymentBrandConfig.Builder()
.setPaypalPayfastConfig(paypalPayfastConfig)
.build()
2. Create Paypal Payfast payment params
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
val paymentParams = PaypalPayFastPaymentParams(checkoutId, Connect.ProviderMode.TEST, paypalPayfastConfig)
// no need to set ShopperResultUrl for PaypalPayfast
3. Submit transaction
Create Transaction object by passing PaypalPayFastPaymentParams, then create payment provider object and call submit transaction.
Transaction transaction = new Transaction(paymentParams);
OppPaymentProvider paymentProvider = new OppPaymentProvider(this, Connect.ProviderMode.TEST);
paymentProvider.submitTransaction(transaction, this);
val transaction = Transaction(paymentParams)
val paymentProvider = OppPaymentProvider(this, Connect.ProviderMode.TEST)
paymentProvider.submitTransaction(transaction, this)
4. Register ActivityResultLauncher object to launch Paypal Payfast launcher to process the transaction
To complete PAYPAL_PAYFAST transaction after you receive a transaction object in the callback of step 3, you have to create ActivityResultLaucher object of PaypalPayfastProcessorResultContract and launch with that transaction.
5. Get the payment status
Finally your app should request the payment status from your server.
For more details you can refer to this document.