The MamoPay PHP library offers seamless integration with the MamoPay API for PHP-based applications, streamlining access and enhancing functionality.
A minimum of PHP 5.6.0 up to 8.1
You can install the package via Composer:
composer require xplicit-dev/mamopay
Obtain your API Key:
Log in to the MamoPay dashboard (https://dashboard.mamopay.com/manage/developer)
and navigate to the Developer section to get your API key.
Instantiate MamoPay Client:
use MamoPay\Api\MamoClient;
$client = (new MamoClient('API_KEY'));
For sandbox testing, pass 'true' as second parameter:
$client = (new MamoClient('API_KEY',true));
The resources can be accessed via the $client
object. All the methods invocations follow the following pattern
// $client->class()->function() to access the API
//Example
$client->links()->get($linkId);
The MamoClient SDK allows you to utilize resources not listed within this package. This flexibility enables you to leverage any additional resources provided by the MamoPay API without constraints.
use MamoPay\Api\MamoClient;
$client = (new MamoClient('API_KEY'));
$params = ['card_id' => $card_id, 'amount' => $amount, 'currency' => $currency];
$response = $client->httpClient->sendRequest('end_point',$params,HttpClient::METHOD_POST);
The resource to generate vanilla and subscription payment links
- generate vanilla payment link:
see params here https://mamopay.readme.io/reference/post_links
$params = ['is_widget' => true , 'save_card'=>true];
$response = $client->links()->create($title,$amount,$returnUrl,$params);
this will return a \MamoPay\Api\Objects\PaymentLink object
refer: https://mamopay.readme.io/reference/payment-link-object
$id = $response->id;
$payment_url = $response->payment_url;
- Fetching all Payment Links:
$client->links()->all();
- Update Payment Link:
$client->links()->update($linkID,$params);
- Delete Payment Link:
$client->links()->delete($linkID);
- Fetch Payment Link Info:
$client->links()->get($linkID);
Initiate transactions by merchant (Merchant Initiated Transaction)
Merchant Initiated Transactions (MIT) allows a business to use card details, that were stored during previous transactions, to charge their customers.
$charge = $client->transaction()->create($card_id,$amount);
this will return a \MamoPay\Api\Objects\TransactionInfo object
refer : https://mamopay.readme.io/reference/charge-object
$chargeID = $charge->id;
- Fetch Transaction Info
$client->transaction()->get($chargeID);
- Fetch all Transactions
$client->transaction()->all();
- Refund Payment
$client->transaction()->refund($chargeId,$amount);
- Fetches all subscribers of subscription.
$client->subscription()->all($subscriptionId);
- Fetches all subscription payments made against a Recurring Payment item.
$client->subscription()->get($subscriptionId);
- Unsubscribe subscription
$client->subscription()->unSubscribe($subscriptionId,$subscriberId);
- Cancels an existing recurring payment. This is NOT to unsubscribe a customer from a recurring payment that they have subscribed to. This deletes a previously created subscription for a business.
$client->subscription()->cancelRecurring($subscriptionId);
- Fetch all Disbursements
$client->payout()->all();
Issue Disbursements
- Allows the issuance of disbursement
$client->payout()->issue($account_no, $amount, $first_name, $last_name = '', $reason = '', $transfer_method = 'BANK_ACCOUNT');
- Allows the issuance of disbursements in bulk
<?php
use MamoPay\Api\Objects\Disbursement;
$client = (new MamoClient());
$disbursement[0] = (new Disbursement())->set([
'account' => 'AE080200000123223333121',
'amount' => 10,
'first_name_or_business_name' => 'John',
'last_name' => 'Doe',
]);
$disbursement[1] = (new Disbursement())->set([
'account' => 'AE080200000123223333121',
'amount' => 20.5,
'first_name_or_business_name' => 'John',
'last_name' => 'Doe',
'reason' => 'refund for lorem ipsum',
]);
$disbursements = $client->payout()->issueMultiple($disbursement);
-Webhook registration for updates on one-off payment statuses and subscription payment statuses.
$client->webhook()->create($uri,$events,'authentication header');
this will return \MamoPay\Api\Objects\WebhookInfo object
- WebhookEvent class contain all event constants
use MamoPay\Api\Events\WebhookEvent;
$response = $client->webhook()->create("http://example.com",WebhookEvent::ALL_EVENT_TYPES,'authentication header');
$response = $client->webhook()->create("http://example.com",[WebhookEvent::CHARGE_CARD_VERIFIED,WebhookEvent::CHARGE_SUCCEEDED]);
$webhookId = $response->id;
- Fetches all registered webhooks for a given business
$client->webhook()->all();
- update webhook details
$client->webhook()->update($webhookId,"http://example.com",WebhookEvent::ALL_EVENT_TYPES,'authentication header');
- Delete a registered webhook
$client->webhook()->delete($webhookId);
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.