0 purchases
tap apple pay flutter
ApplePay-Flutter #
A flutter sdk provided by Tap Payments, to accept Apple Pay payments within your Flutter applications.
Getting started #
In the pubspec.yaml of your flutter project, add the following dependency:
dependencies:
tap_apple_pay_flutter: 1.0.3
copied to clipboard
In your library add the following import:
import 'package:tap_apple_pay_flutter/models/models.dart';
copied to clipboard
Then execute this in flutter terminal:
cd ios
pod install
pod update
copied to clipboard
Minimum requirements #
Dart version 3.0.0 +
Flutter version 3.0.0 +
iOS 13.0 +
SDK response format #
Through out, the interaction of your app with Tap Apple Pay SDK, we made sure you will get the same response format to ease the parsing process your end.
The format will always be as follows:
Success case:
{'success':true,'data':''}
So when success is true, this means the process is completed successfully.
data is an optional object, will pass back any data expected as a result of the performed action.
Error case:
{'success':false,'error':''}
So when success is false, this means the process failed.
error is a string that will identify which error did occur.
Pre rendering setup #
A setup is needed to be done, before rendering the Apple Pay widget. These configurations, will define to the Apple Pay widget the data required for tokenization & styling afterwards. Following is a code snippet example, of how to setup Apple Pay widget.
Future<void> setupApplePay(
// This is the testing key, provided upon registering your bundle id in Tap
{String sandboxKey = "pk_test_Vlk842......",
// This is the production key, provided upon registering your bundle id in Tap
String productionKey = "pk_live_UYnihb.....",
// This is the sdk mode enum, defines the environment your application is running in.
// Accepted values are : SdkMode.sandbox / SdkMode.production
required SdkMode sdkMode}) async {
// Store your data in our plugin level
TapApplePayFlutter.setupApplePayConfiguration(
sandboxKey: sandboxKey,
productionKey: productionKey,
sdkMode: sdkMode,
);
try {
// Now we call a public interface provided by Apple pay flutter sdk.
// It is of type future, and the response will follow the structure described before.
var result = await TapApplePayFlutter.setupApplePay;
if(result["success"]) {
debugPrint("Apple pay plugin is configured properly.");
}else{
debugPrint("Apple pay plugin configuration failed : $result["error"]");
}
} catch (ex) {
debugPrint("Error >>>>>>> $ex");
}
}
copied to clipboard
Then from your code anywhere before rendering the widget call it like it this:
setupApplePay(
sandboxKey: "",
productionKey: "",
sdkMode: widget.sdkMode,
);
copied to clipboard
Adding the Apple Pay widget #
Within your widget hierarchy, you can add our Apple Pay widget as normally as you do with native provided widgets. A sample is as follows:
TapApplePayFlutter.buildApplePayButton( // The button widget
applePayButtonType: ApplePayButtonType.appleLogoOnly, // Defines the type of apple pay button. it is one of the provided values by [Apple](https://developer.apple.com/documentation/apple_pay_on_the_web/applepaybuttontype)
applePayButtonStyle: ApplePayButtonStyle.black,
onPress: () { // This will be fired once the widget is clicked Optional.
getApplePayToken(); // A sample code below to show how to generate a raw apple pay token
getTapTokenToken(); // A sample code below to show how to generate a Tap token that can be used to charge the customer through Tap apis.
},
)
copied to clipboard
Generating Apple Pay token #
You can ask our plugin to authorize a payment from Apple Pay system, and provide you back with the raw Apple Pay token for your own further usages. Make sure you already called the setup process we indicated above before calling this interface.
A sample code to generate the Apple Pay token is as follows:
/// A sample function simulating how can you ask our plugin to generate a raw apple pay token
Future<void> getApplePayToken() async {
try {
// our interface is of future type.
var result = await TapApplePayFlutter.getApplePayToken(
config: ApplePayConfig(
transactionCurrency: TapCurrencyCode.SAR, // A 3 iso digits currency code. We have created a list of enums to prevent typos.
allowedCardNetworks: [ // Define the list of allowed card schemes for your customer to pay with
AllowedCardNetworks.AMEX,
AllowedCardNetworks.VISA,
AllowedCardNetworks.MASTERCARD,
],
applePayMerchantId: "merchant.tap.gosell", // This is the apple pay merchant id you created and linked with your apple pay certificate from within your apple pay developer account
amount: 1.0, // The total amount
merchantCapabilities: [ // The allowed card funding sources your customer can pay with
MerchantCapabilities.ThreeDS,
MerchantCapabilities.Debit,
MerchantCapabilities.Credit,
],
),
);
if(result["success"]) {
debugPrint("Result of Apple Pay Token >>>>>>> $result");
}else{
debugPrint("Error of Apple Pay Token >>>>>>> $result");
}
} catch (ex) {
debugPrint("Error >>>>>>> $ex");
}
}
copied to clipboard
Generating Tap Apple Pay token #
You can ask our plugin to authorize a payment from Apple Pay system, and then generate a Tap token for it. By that token, you can perform a charge through our APIS. Make sure you already called the setup process we indicated above before calling this interface.
A sample code to generate the Tap Apple Pay token is as follows:
/// A sample function simulating how can you ask our plugin to generate a tap apple pay token
Future<void> getTapTokenToken() async {
try {
// our interface is of future type.
var result = await TapApplePayFlutter.getTapToken(
config: ApplePayConfig(
transactionCurrency: TapCurrencyCode.SAR, // A 3 iso digits currency code. We have created a list of enums to prevent typos.
allowedCardNetworks: [ // Define the list of allowed card schemes for your customer to pay with
AllowedCardNetworks.AMEX,
AllowedCardNetworks.VISA,
AllowedCardNetworks.MASTERCARD,
],
applePayMerchantId: "merchant.tap.gosell", // This is the apple pay merchant id you created and linked with your apple pay certificate from within your apple pay developer account
amount: 1.0, // The total amount
merchantCapabilities: [ // The allowed card funding sources your customer can pay with
MerchantCapabilities.ThreeDS,
MerchantCapabilities.Debit,
MerchantCapabilities.Credit,
],
),
);
if(result["success"]) {
debugPrint("Result of Tap Apple Pay Token >>>>>>> $result");
}else{
debugPrint("Error of Tap Apple Pay Token >>>>>>> $result");
}
} catch (ex) {
debugPrint("Error >>>>>>> $ex");
}
}
copied to clipboard
Xcode needed setup #
You will need to add Apple Pay as a capability inside your project's settings in Xcode. And select the Apple Pay merchant id you are passing to our plugin.
Integration needed steps: #
Onboard with Tap at Tap Payments
Register your bundle id.
Ask for Apple Pay CSR from our integration team.
Go to your Apple Pay developer account Certificates
Click on Add certificate
Choose Apple Pay payment processing certificate
Select the Apple Pay merchant id. Make sure, it is the one you will pass inside the Xcode
Upload the CSR you got from Tap team.
Download the Apple Pay certificate and share it back to the Tap team
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.