Summary
This flutter plugin is a wrapper around our Android SDK. To know more about our SDKs and how to link them within the projects, refer to the documentation
Pre-Requisites
Payment Token:
A payment token represents an order or a purchase. The first step to open up a payment page on your app is to create a payment_token. A payment_token can be created by referring to create payment token API. This API should be always called from your server. You will receive payment_token as a response.
Access Token:
Access key is a unique key which you can generate from your OPEN dashboard.
Android
Change the minSdkVersion
in your build.gradle file in the android/app/build.gradle
has
minSdkVersion 19
Get Started
Installation
dependencies:
open_payment: ^0.0.1
Import
import 'package:open_payment/open_payment.dart';
Usage
Calling initiate payment function on click of button
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.add),
onPressed: onPaymentClick,
)
onPaymentClick function
Future<void> onPaymentClick() async {
OpenPaymentPayload openPaymentPayload = OpenPaymentPayload(
accessToken: accessToken,
paymentToken: paymentToken,
environment: environment,
);
await OpenPayment.initiatePayment(
openPaymentPayload: openPaymentPayload,
onTransactionComplete: (TransactionDetails transactionDetails) {
// Handle transaction result
},
onError: (String error) {
// Handle integration error
});
}
To see the whole implementation check example
Initialize OpenPaymentPayload
You need to create a payload with the following parameters:
Parameter | Description |
---|---|
accessToken(Mandatory) | Access key is a unique key which you can generate from your Open dashboard. Throws exception in case of empty string |
paymentToken(Mandatory) | To create the token using Create Payment Token API. Throws exception in case of empty string |
environment(Mandatory) | Following ENUM can be passed to this method.PaymentEnvironment.live and PaymentEnvironment.sandbox |
logoUrl | Logo is changed to image source passed. |
mainColor | Main color of Layer will be changed to this . Example: #f8c5c5 |
errorColor | Error color (icons/ error lines / error messages) of Layer will be changed to this . Example: #83025c |
onTransactionComplete implementation:
This is called whenever transaction is completed. Along with TransactionDetails passed as parameter.
TransactionDetails.status
may either captured
, failed
, pending
and cancelled
.
NOTE - If onTransactionComplete is invoked it doesn't means that payment is successful. It may fail but transaction is completed is the only purpose.
onTransactionComplete: (TransactionDetails transactionDetails) {
// Handle transaction result
}
onError implementation:
This is called whenever there is an integration errors.
onError: (String error) {
// Handle integration error
}