-
Notifications
You must be signed in to change notification settings - Fork 19
Direct Charge
The charge APIs help you to collect payments using different payment methods.
Before using any of the function, make sure you call the bootstrap function.
use Flutterwave\Flutterwave;
Flutterwave::bootstrap().
Direct card charge allows you to charge both local cards (issued in your country of operation) and international cards. This is useful if your customers are predominantly credit/debit card users, and you'd prefer for them to manage payments via your app.
use Flutterwave\Util\Currency;
$data = [
"amount" => 2000,
"currency" => Currency::NGN,
"tx_ref" => "TEST-".uniqid().time(),
"redirectUrl" => "https://www.example.com",
"additionalData" => [
"subaccounts" => [
["id" => "RSA_345983858845935893"]
],
"meta" => [
"unique_id" => uniqid().uniqid()
],
"preauthorize" => false,
"payment_plan" => null,
"card_details" => [
"card_number" => "5531886652142950",
"cvv" => "564",
"expiry_month" => "09",
"expiry_year" => "32"
]
],
];
$cardpayment = \Flutterwave\Flutterwave::create("card");
$customerObj = $cardpayment->customer->create([
"full_name" => "Olaobaju Abraham",
"email" => "[email protected]",
"phone" => "+234900154861"
]);
$data['customer'] = $customerObj;
$payload = $cardpayment->payload->create($data);
$result = $cardpayment->initiate($payload);
print_r($result);
Once the charge and validation process is complete for the first charge on the card, you can make use of the token for subsequent charges. Your second charge should look like the snippet below.
use Flutterwave\Util\Currency;
$data = [
"amount" => 2000,
"currency" => Currency::NGN,
"tx_ref" => uniqid().time(),
"redirectUrl" => null,
"additionalData" => [
"token" => "flw-t0-fe20067f9d8d3ce3d06f93ea2d2fea28-m03k"
]
];
$data['redirectUrl'] = "http://{$_SERVER['HTTP_HOST']}/examples/endpoint/verify.php?tx_ref={$data['tx_ref']}";
$customerObj = $tokenpayment->customer->create([
"full_name" => "Olaobaju Jesulayomi Abraham",
"email" => "[email protected]",
"phone" => "+2349062947561"
]);
$data['customer'] = $customerObj;
$tokenpayment = \Flutterwave\Flutterwave::create("tokenize");
$payload = $tokenpayment->payload->create($data);
$result = $tokenpayment->initiate($payload);
Direct account charge allows you to collect payments directly from your customers' bank accounts.
There are three "flavours" of direct bank account charge, depending on the bank account's currency/country:
- Direct debit (for Nigerian accounts): The customer authorizes the payment with their bank, and the money is debited from their account.
- UK (GBP) accounts: The customer logs in to their bank's Internet/mobile banking and makes a transfer to a generated bank account.
use Flutterwave\Util\Currency;
$data = [
"amount" => 2000,
"currency" => Currency::NGN, // or EUR or GBP for EU Collection.
"tx_ref" => uniqid().time(),
"additionalData" => [
"account_details" => [
"account_bank" => "044",
"account_number" => "0690000034",
"country" => "NG"
]
],
];
$accountpayment = \Flutterwave\Flutterwave::create("account");
$customerObj = $accountpayment->customer->create([
"full_name" => "Guy Herman Lerman",
"email" => "[email protected]",
"phone" => "+2349067985861"
]);
$data['customer'] = $customerObj;
$payload = $accountpayment->payload->create($data);
$result = $accountpayment->initiate($payload);
ACH payment (for USD and ZAR accounts)
use Flutterwave\Util\Currency;
$data = [
"amount" => 2000,
"currency" => Currency::ZAR,
"tx_ref" => uniqid().time(),
"redirectUrl" => "https://google.com"
];
$achpayment = \Flutterwave\Flutterwave::create("ach");
$customerObj = $achpayment->customer->create([
"full_name" => "Bourne Jason Abraham",
"email" => "[email protected]",
"phone" => "+2349067985861"
]);
$data['customer'] = $customerObj;
$payload = $achpayment->payload->create($data);
$result = $achpayment->initiate($payload);
use Flutterwave\Util\Currency;
$data = [
"amount" => 2000,
"currency" => Currency::XOF,
"tx_ref" => uniqid().time(),
"redirectUrl" => null,
"additionalData" => [
"network" => "MTN",
]
];
$momopayment = \Flutterwave\Flutterwave::create("momo");
$customerObj = $momopayment->customer->create([
"full_name" => "John Snow Targ",
"email" => "[email protected]",
"phone" => "+2259060085861"
]);
$data['customer'] = $customerObj;
$payload = $momopayment->payload->create($data);
$result = $momopayment->initiate($payload);
use Flutterwave\Util\Currency;
$data = [
"amount" => 2000,
"currency" => Currency::GHS,
"tx_ref" => uniqid().time(),
"redirectUrl" => null,
"additionalData" => [
"network" => "MTN",
]
];
$momopayment = \Flutterwave\Flutterwave::create("momo");
$customerObj = $momopayment->customer->create([
"full_name" => "Jean Grey",
"email" => "[email protected]",
"phone" => "+23390670800000"
]);
$data['customer'] = $customerObj;
$payload = $momopayment->payload->create($data);
$result = $momopayment->initiate($payload);
use Flutterwave\Util\Currency;
$data = [
"amount" => 2000,
"currency" => Currency::UGX,
"tx_ref" => uniqid().time(),
"redirectUrl" => null,
"additionalData" => [
"network" => "AIRTEL",
]
];
$momopayment = \Flutterwave\Flutterwave::create("momo");
$customerObj = $momopayment->customer->create([
"full_name" => "Logan Wolverine",
"email" => "[email protected]",
"phone" => "+2569060000800"
]);
$data['customer'] = $customerObj;
$payload = $momopayment->payload->create($data);
$result = $momopayment->initiate($payload);
use Flutterwave\Util\Currency;
$data = [
"amount" => 2000,
"currency" => Currency::TZS,
"tx_ref" => uniqid().time(),
"redirectUrl" => null,
"additionalData" => [
"network" => "AIRTEL",
]
];
$momopayment = \Flutterwave\Flutterwave::create("momo");
$customerObj = $momopayment->customer->create([
"full_name" => "Magnus Rogue",
"email" => "[email protected]",
"phone" => "+2559000085861"
]);
$data['customer'] = $customerObj;
$payload = $momopayment->payload->create($data);
$result = $momopayment->initiate($payload);
If you're collecting money in KES, your customers can pay with M-Pesa.
- Create a charge, passing in the customer's mobile number.
- Customer completes the payment by authorising it from their M-Pesa app.
use Flutterwave\Util\Currency;
$data = [
"amount" => 2000,
"currency" => Currency::KES,
"tx_ref" => uniqid().time(),
"redirectUrl" => "https://google.com"
];
$mpesapayment = \Flutterwave\Flutterwave::create("mpesa");
$customerObj = $mpesapayment->customer->create([
"full_name" => "Olaobaju Jesulayomi Abraham",
"email" => "[email protected]",
"phone" => "+2349067985861"
]);
$data['customer'] = $customerObj;
$payload = $mpesapayment->payload->create($data);
$result = $mpesapayment->initiate($payload);
print_r($result);
Direct charge via bank transfer allows you to generate account details (account number and bank) on demand to receive payments from customers via bank transfer.
$data = [
"amount" => 2000,
"currency" => Currency::NGN,
"tx_ref" => uniqid().time(),
"redirectUrl" => "https://google.com"
];
$btpayment = Flutterwave::create("bank-transfer");
$customerObj = $btpayment->customer->create([
"full_name" => "Olaobaju Jesulayomi Abraham",
"email" => "[email protected]",
"phone" => "+2349067985011"
]);
$data['customer'] = $customerObj;
$payload = $btpayment->payload->create($data);
$result = $btpayment->initiate($payload);
print_r($result);
Direct USSD charge allows you to collect payments via USSD. With USSD charge, you call our API to create a charge, then your customer completes the payment by dialling their bank's USSD code on their mobile phone. Once the payment is completed, we'll notify you via webhook.
use Flutterwave\Util\Currency;
$data = [
"amount" => 2000,
"currency" => Currency::NGN,
"tx_ref" => uniqid().time(),
"redirectUrl" => null,
"additionalData" => [
"account_bank" => "044",
"account_number" => "000000000000"
]
];
$ussdpayment = \Flutterwave\Flutterwave::create("ussd");
$customerObj = $ussdpayment->customer->create([
"full_name" => "Olaobaju Jesulayomi Abraham",
"email" => "[email protected]",
"phone" => "+2349067985861"
]);
$data['customer'] = $customerObj;
$payload = $ussdpayment->payload->create($data);
$result = $ussdpayment->initiate($payload);
Apple Pay offers a great experience for customers with iOS devices. With this payment method, you can integrate directly to the Apple checkout on your website (or store).
$data = [
"amount" => 2000,
"currency" => Currency::NGN,
"tx_ref" => uniqid().time(),
"redirectUrl" => "https://example.com"
];
$applepayment = \Flutterwave\Flutterwave::create("apple");
$customerObj = $applepayment->customer->create([
"full_name" => "Olaobaju Jesulayomi Abraham",
"email" => "[email protected]",
"phone" => "+2349060085861"
]);
$data['customer'] = $customerObj;
$payload = $applepayment->payload->create($data);
$result = $applepayment->initiate($payload);
print_r($result);
With Google Pay, Customers can make payments with cards linked to their Google accounts. They can choose from these linked cards to make one-touch payments on the modal. This payment experience elevates UX in your application.
$data = [
"amount" => 2000,
"currency" => Currency::NGN,
"tx_ref" => uniqid().time(),
"redirectUrl" => "https://example.com"
];
$googlepayment = \Flutterwave\Flutterwave::create("google");
$customerObj = $googlepayment->customer->create([
"full_name" => "Olaobaju Jesulayomi Abraham",
"email" => "[email protected]",
"phone" => "+2349060085861"
]);
$data['customer'] = $customerObj;
$payload = $googlepayment->payload->create($data);
$result = $googlepayment->initiate($payload);
print_r($result);
eNaira is a digital currency issued and regulated by the Central bank of Nigeria (CBN). With this method, Customers can make payments with eNaira wallets linked to their bank accounts.
use Flutterwave\Util\Currency;
$data = [
"amount" => 2000,
"is_token" => 1,
"currency" => Currency::NGN,
"tx_ref" => uniqid().time(),
"redirectUrl" => "https://example.com"
];
$payment = \Flutterwave\Flutterwave::create("enaira");
$customerObj = $payment->customer->create([
"full_name" => "Olaobaju Jesulayomi Abraham",
"email" => "[email protected]",
"phone" => "+2349060085861"
]);
$data['customer'] = $customerObj;
$payload = $payment->payload->create($data);
$result = $payment->initiate($payload);
print_r($result);
Fawry payments are agency-based payments that are initiated by users online to be completed offline. With this payment method, customers can make seamless payments over the counter to a wide range of connected agent networks.
use Flutterwave\Util\Currency;
$data = [
"amount" => 2000,
"currency" => Currency::EGP,
"tx_ref" => uniqid().time(),
"redirectUrl" => "https://example.com"
];
$payment = \Flutterwave\Flutterwave::create("fawry");
$customerObj = $payment->customer->create([
"full_name" => "Olaobaju Jesulayomi Abraham",
"email" => "[email protected]",
"phone" => "+2349060085861"
]);
$data['customer'] = $customerObj;
$payload = $payment->payload->create($data);
$result = $payment->initiate($payload);