With this module, developers can effortlessly integrate Vanilla Pay International's payment service into their cross-platform Flutter applications.
The Vanilla Pay International Dart package provides a convenient way to integrate Vanilla Pay International services into your Flutter applications (Android & iOs). It allows you to generate tokens, initialize payments, check transaction statuses, and validate data authenticity with ease.
To use this package, add vanilla_pay_international
as a dependency in your pubspec.yaml
file:
dependencies:
vanilla_pay_international: ^1.0.0
Then, run flutter pub get
to install the package.
To use the Vanilla Pay International services, you need to initialize a VanillaPay
instance:
import 'package:vanilla_pay_international/vanilla_pay_international.dart';
void main() {
VanillaPay paymentManager = VanillaPay(
env: 'PROD',
vpiVersion: '1.0.0',
clientId: 'your_client_id',
clientSecret: 'your_client_secret',
keySecret: 'your_key_secret',
);
}
Use the generateToken()
method to generate a token, which remains valid for 20 minutes:
TokenResponse? tokenResponse = await paymentManager.generateToken();
Response (tokenResponse):
{
"CodeRetour": 200,
"DescRetour": "Génération TOKEN.",
"DetailRetour": "",
"Data": {
"Token": "Bearer <token>"
}
}
Initiate a payment process using the initializePayment()
method:
token
: The generated token.montant
: The amount of the transaction.devise
: The currency of the transaction (e.g EUR).reference
: The pro external reference.panier
: The identifier for the transaction.notifUrl
: URL called when the payment is finished.redirectUrl
: URL to redirect the customer after completing the payment.
InitPaymentResponse? initPaymentResponse = await paymentManager.initializePayment(
token,
montant,
devise,
reference,
panier,
notifUrl,
redirectUrl,
);
Response (initPaymentResponse):
{
"CodeRetour": 200,
"DescRetour": "Génération lien de paiement.",
"DetailRetour": "",
"Data": {
"url": "https://link.com"
}
}
Retrieve the status of a transaction using the getTransactionsStatus()
method:
token
: The generated token.paymentLink
: The payment link.
TransactionStatusResponse? transactionStatusResponse = await paymentManager.checkTransactionStatus(
token,
paymentLink,
);
Response (status):
{
"CodeRetour": 200,
"DescRetour": "Transaction status.",
"DetailRetour": "",
"Data": {
"reference_VPI": "VPI23011201010101",
"panier" : "panier123",
"reference": "ABC-1234",
"montant": 58.5,
"etat": "SUCCESS"
}
}
Validate the authenticity of provided data using the validateDataAuthenticity()
method:
vpiSignature
: The signature extracted from the headers.body
: The data to be hashed and compared against the signature.
bool isAuthentic = paymentManager.validateDataAuthenticity(vpiSignature, body);
Contributions and bug reports are welcome! Please feel free to submit a pull request or open an issue on the GitHub repository: Here.
Copyright © 2024 Vanilla Pay. All rights reserved.