PHP code example of xplicit-dev / mamopay

1. Go to this page and download the library: Download xplicit-dev/mamopay library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xplicit-dev / mamopay example snippets


use MamoPay\Api\MamoClient;


$client = (new MamoClient('API_KEY'));

$client = (new MamoClient('API_KEY',true));

// $client->class()->function() to access the API

//Example

$client->links()->get($linkId);

$client->me();

$client->mybalance();

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);

$params = ['is_widget' => true , 'save_card'=>true];

$response = $client->links()->create($title,$amount,$returnUrl,$params);

// subscription payment link (recommended): create the subscription first, then attach it
$subscription = $client->subscription()->create('monthly', 1);
$params = ['link_type' => 'inline', 'subscription_id' => $subscription->identifier];
$response = $client->links()->create($title,$amount,$returnUrl,$params);

$id = $response->id;

$payment_url = $response->payment_url;

$client->links()->all();

$client->links()->update($linkID,$params);

$client->links()->delete($linkID);

$client->links()->get($linkID);

$charge = $client->transaction()->create($card_id,$amount);

$chargeID = $charge->id;

$client->transaction()->get($chargeID);

$client->transaction()->all($page, $perPage);

$client->transaction()->get($chargeID);

$client->transaction()->capture($chargeId,$amount);

$client->transaction()->reverse($chargeId);

$client->transaction()->refund($chargeId,$amount);

$client->subscription()->all($subscriptionId);

$client->subscription()->get($subscriptionId);

$client->subscription()->unSubscribe($subscriptionId,$subscriberId);

$client->subscription()->cancelRecurring($subscriptionId);

$response = $client->subscription()->create($frequency,$frequency_interval,$end_date,$payment_quantity,$weekly_start_day,$monthly_start_date);

// frequency: 'daily', 'weekly', 'monthly', 'annually', 'test' (daily and test are sandbox-only)
// e.g. monthly subscription starting on the 5th:
$response = $client->subscription()->create('monthly', 1, '', null, '', 5);

$subscriptionId = $response->id;

$client->subscription()->changeCustomerSubscription($subscriptionId,$subscriberId,$targetSubscriptionId);

$client->payout()->all();

// with pagination (documented query params page / per_page)
$client->payout()->all($page, $perPage);

$client->payout()->issue($account_no, $amount, $first_name, $last_name = '', $reason = '', $transfer_method = 'BANK_ACCOUNT');

// pay out to a saved recipient instead of raw bank details (optional trailing params)
$client->payout()->issue(null, $amount, '', '', $reason, 'BANK_ACCOUNT', $recipient_id);


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',
]);

// payouts to saved recipients can also be issued in bulk via the recipient_id property
$disbursement[2] = (new Disbursement())->set([
'recipient_id' => 'REP-6BB7CA8DC7',
'amount' => 15,
'reason' => 'payout to saved recipient',
]);

$disbursements = $client->payout()->issueMultiple($disbursement);

$response = $client->payout()->createInternational($recipient_id,$reason,$source_amount,null,'description');

// an Idempotency-Key header is always sent; pass your own as the last argument to control retries
$response = $client->payout()->createInternational($recipient_id,$reason,$source_amount,null,'description','my-idempotency-key');

$client->webhook()->create($uri,$events,'authentication header');

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;

$client->webhook()->all();

$client->webhook()->update($webhookId,"http://example.com",WebhookEvent::ALL_EVENT_TYPES,'authentication header');

$client->webhook()->delete($webhookId);

$client->webhook()->deleteAll();

$client->recipient()->all();

$recipient = (new RecipientInfo())->set([
    'recipient_type' => RecipientInfo::RECIPIENT_TYPE_INDIVIDUAL,
    'first_name' => 'John',
    'last_name' => 'Doe',
    'email' => '[email protected]',
    'relationship' => RecipientInfo::RELATIONSHIP_CUSTOMER,
    'reason' => 'Payment for services',
    'eid_number' => '784-XXXX-XXXXXXX-0',
    'address' => (new Address())->set([
        'address_line1' => '123 Main Street',
        'address_line2' => 'Apt 4B',
        'city' => 'Dubai',
        'state' => 'AE',
        'country' => 'AE'
    ]),
    'bank' => (new Bank())->set([
        'iban' => 'AE080200000123223333121',
        'account_number' => '123223333121',
        'name' => 'ABC Bank',
        'bic_code' => 'ABCDUAE123',
        'address' => 'XYZ Bank Tower, Dubai',
        'country' => 'AE'
    ])
]);

$client->recipient()->create($recipient)

this will return a \MamoPay\Api\Objects\RecipientInfo object

$recipient = (new RecipientInfo())->set([
    'recipient_type' => RecipientInfo::RECIPIENT_TYPE_INDIVIDUAL,
    'first_name' => 'John',
    'last_name' => 'Doe',
    'email' => '[email protected]',
    'relationship' => RecipientInfo::RELATIONSHIP_CUSTOMER,
    'reason' => 'Payment for services',
    'eid_number' => '784-XXXX-XXXXXXX-0',
    'address' => (new Address())->set([
        'address_line1' => '123 Main Street',
        'address_line2' => 'Apt 4B',
        'city' => 'Dubai',
        'state' => 'AE',
        'country' => 'AE'
    ]),
    'bank' => (new Bank())->set([
        'iban' => 'AE080200000123223333121',
        'account_number' => '123223333121',
        'name' => 'ABC Bank',
        'bic_code' => 'ABCDUAE123',
        'address' => 'XYZ Bank Tower, Dubai',
        'country' => 'AE'
    ])
]);

$client->recipient()->update($recipientID,$recipient);

this will return a \MamoPay\Api\Objects\RecipientInfo object

recipientID is the recipient identifier returned when creating a recipient.


$client->recipient()->get($recipientID)


$client->recipient()->delete($recipientID);

$client->recipient()->balance($recipientID);

$response = $client->recipient()->validateIban('AE070331234567890123456');

// $response->valid, $response->bank_name, $response->bic_code (or $response->errors when invalid)

 $client->card()->create(float $amount, string $email, string $booking_id='', string $verification_email = '', array $params = []);
 

$response = $client->card()->createPartnerCard($amount,$email,$booking_id,$verification_email,$transactions_limit);

$client->card()->listPartnerCards($page, $perPage);

$client->card()->getPartnerCard($identifier);

$client->card()->updatePartnerCard($identifier,$amount);

$client->card()->cancelPartnerCard($identifier);

$client->card()->listPartnerCardTransactions($identifier,$page, $perPage);

$client->card()->getPartnerCardTransaction($identifier,$transaction_identifier);

$client->card()->transactions($page, $perPage);

$client->card()->getTransaction($transactionId);

$client->card()->updateExpense($expenseId,$invoice_number,$description,$status);

$client->card()->expenseReceipts($page, $perPage);

$client->card()->getExpenseReceipt($identifier);

$response = $client->invoice()->create(
    amount: 100.00,
    email: '[email protected]',
    amount_currency: 'AED',   // AED, USD, EUR, GBP or SAR
    description: 'Consulting services',
);

// additional documented options are available as optional params:
// customer_type, first_name, last_name, phone_number, vat_enabled,
// plus via $params: additional_heading, additional_details, additional_cc_emails,
// 
bash
export MAMO_API_KEY="your-sandbox-key"
export MAMO_SANDBOX=true            # false for production keys
export MAMO_RUN_INTEGRATION=1       # integration tests skip without this
export MAMO_WEBHOOK_URL="https://your-public-endpoint/hook"   # optional; must be publicly reachable

vendor/bin/phpunit --testsuite Integration