credo_gateway 0.0.2
credo_gateway: ^0.0.2 copied to clipboard
Official plugin for Credo Payment gateway https://credocentral.com/
flutter-credo-sdk #
Credo SDK Flutter #
This library allows for the easy integration of [Credo] into your Flutter application. It shoulders the burden of PCI compliance by sending credit card details directly to Credo's servers rather than to your server.
Flow Summary #
-
Collect user's card details, email and phone number.
-
Initialize the CredoPlugin by creating an object of the CredoPlugin class with two named parameters passed to the constructor.
- The first argument is the public key of the merchant
- The second argument is the secret key of the merchant.
- Both public and secret keys are provided by Credo to the merchants.
- Prompts backend to initialize transactions by calling the
initialPaymentmethod. - Credo's backend returns a
payment slugwhich is returned whenInitiate Paymentendpoint is called - App provides the
payment slugand card details to our SDK's using thepayandverifyCardNumbermethods
-
Once request is successful,
ThirdPartyPaymentResponseis return.
Installation #
- To start using this package, simply add the following to project
pubspec.yaml
flutter_credo: <lastes-version>
Usage #
1. Permissions #
To use this package, your android app must declare internet permission. Add the following code to the application level of your AndroidManifest.xml.
<uses-permission android:name="android.permission.INTERNET" />
2. Initializing SDK #
To use [Credo] SDK, you need to first initialize it by using the `CredoPlugin` class.
CredoPlugin credoPlugin = CredoPlugin(
publicKey: 'public_key',
);
Ensure to perform this instantiation in the initState method of your Widget.
CredoPlugin credoPlugin;
@override
void initState() {
credoPlugin = CredoPlugin(
publicKey: 'pk_demo-cKwtbsYaPNjgZZIFfznnZJGP49plbw.ujlZ0XcwAD-d',
);
initPayment();
super.initState();
}
3. Initiate Payment #
Payment transaction can be initiated with the initialPayment method:
Parameters #
amountThe amount to be transacted.currencyThe currency to be transacted in.redirectUrlThe url to redirect to after transaction.transRef[optional] The transaction reference for the paymentpaymentOptionsoption can be "CARD" or "USSD" or "BANK"customerNameName of the customercustomerEmailEmail address of the customercustomerPhonePhone number of the customer If the method call is success aInitPaymentResponseis returned from theFutureelse it throws aCredoExceptionwith an error message.
.
.
.
try{
InitPaymentResponse initPaymentRes = await credoPlugin.initialPayment(
amount: 100.0,
currency: 'NGN',
customerEmail: 'info@charlesarchibong.com',
customerName: 'Charles Archibong',
customerPhoneNo: '000000000000',
);
}catch(e){
if(e is CredoException){
print(e.message);
}
}
4. Make payment with Credo Web UI #
Payment transaction can be made with the payWithWebUI method:
Parameters #
amountThe amount to be transacted.currencyThe currency to be transacted in.redirectUrlThe url to redirect to after transaction.transRef[optional] The transaction reference for the paymentpaymentOptionsoption can be "CARD" or "USSD" or "BANK"customerNameName of the customercustomerEmailEmail address of the customercustomerPhonePhone number of the customer If the method call is successful, aWebview to complete the paymentis returned from theFutureelse it throws aCredoExceptionwith an error message.
.
.
.
try{
await credoPlugin.payWithWebUI(
amount: 100.0,
currency: 'NGN',
customerEmail: 'info@charlesarchibong.com',
customerName: 'Charles Archibong',
customerPhoneNo: '000000000000',
);
}catch(e){
if(e is CredoException){
print(e.message);
}
}
After payment, you can call the verifyTransaction which returns VerifyTransactionResponse to verify the payment and confirm all is good.
you can check out the example app for more information.