PHP code example of m0d1xd / tap-company-sdk

1. Go to this page and download the library: Download m0d1xd/tap-company-sdk 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/ */

    

m0d1xd / tap-company-sdk example snippets


Tap::dump()->charges()->create($payload); // print, then send
Tap::dd()->charges()->create($payload);   // print and halt before sending

'secret_key' => 'sk_test_xxx',
'webhook' => [
    'enabled' => true,
    'path' => 'payments/tap/webhook',
],

use TapCompany\LaravelSdk\Facades\Tap;

public function boot(): void
{
    Tap::configure([
        'secret_key' => $this->resolveTapSecret(),
        'merchant_id' => 'merchant_xxx',
        'webhook' => [
            'enabled' => true,
            'path' => 'payments/tap/webhook',
        ],
    ]);
}

use TapCompany\LaravelSdk\Facades\Tap;

$charge = Tap::charges()->create([
    'amount' => 10,
    'currency' => 'KWD',
    'customer' => [
        'first_name' => 'John',
        'email' => '[email protected]',
        'phone' => [
            'country_code' => '965',
            'number' => '50000000',
        ],
    ],
    'source' => ['id' => 'src_all'],
    'redirect' => ['url' => route('checkout.callback')],
    'post' => ['url' => route('tap.webhook')],
]);

return redirect()->away(data_get($charge->toArray(), 'transaction.url'));

Tap::charges()->create($payload, idempotencyKey: $order->id);

use TapCompany\LaravelSdk\Data\PaymentSource;

Tap::charges()->create([
    'amount' => 10,
    'currency' => 'KWD',
    'customer' => ['first_name' => 'John', 'email' => '[email protected]'],
    'source' => PaymentSource::knet(), // or ->all(), ->card(), ->applePay(), ->mada(), ->fawry(), ->stcPay(), ...
    'redirect' => ['url' => route('checkout.callback')],
]);

// A previously saved card or token also has a typed constructor:
PaymentSource::savedCard('card_xxx');
PaymentSource::token('tok_xxx');

use TapCompany\LaravelSdk\Enums\ChargeStatus;

$status = ChargeStatus::from($charge['status']);

if ($status->isSuccessful()) {
    // ...
}

$auth = Tap::authorizations()->create([
    'amount' => 25,
    'currency' => 'SAR',
    'customer' => ['first_name' => 'Jane', 'email' => '[email protected]'],
    'source' => ['id' => 'src_card'],
    'redirect' => ['url' => route('checkout.callback')],
]);

// Later: capture authorized funds
$charge = Tap::authorizations()->capture($auth->id(), [
    'amount' => 25,
    'currency' => 'SAR',
    'customer' => ['id' => $auth->customer['id']],
]);

$refund = Tap::refunds()->create([
    'charge_id' => 'chg_xxx',
    'amount' => 10,
    'currency' => 'KWD',
    'reason' => 'requested_by_customer',
]);

$customer = Tap::customers()->create([
    'first_name' => 'John',
    'email' => '[email protected]',
]);

$token = Tap::tokens()->createFromSavedCard([
    'saved_card' => [
        'card_id' => 'card_xxx',
        'customer_id' => $customer->id(),
    ],
]);

$cards = Tap::cards()->list($customer->id());

$invoice = Tap::invoices()->create([/* ... */]);

$intent = Tap::intents()->create([/* POS payload */]);
Tap::intents()->cancel($intent->id());

$lead = Tap::leads()->create([/* merchant lead */]);
$connect = Tap::connect()->createUrl($lead->id());

$business = Tap::businesses()->create([/* ... */]);
$merchant = Tap::merchants()->create(['business_id' => $business->id()]);
$destination = Tap::destinations()->retrieve('dest_xxx');

Tap::files()->create(
    ['purpose' => 'identity_document'],
    ['path' => storage_path('app/kyc.pdf'), 'name' => 'file', 'filename' => 'kyc.pdf'],
);

$payout = Tap::payouts()->retrieve('pay_xxx');
$csv = Tap::charges()->download(['period' => [/* ... */]]);
$zip = Tap::payouts()->download([/* ... */]);
$disputes = Tap::disputes()->download([/* ... */]);

use TapCompany\LaravelSdk\Events\ChargeUpdated;

Event::listen(ChargeUpdated::class, function (ChargeUpdated $event): void {
    $charge = $event->payload;
    // sync order from $charge->id(), $charge['status'], etc.
});

Tap::webhooks()->validateOrFail($request->all(), $request->header('hashstring'));
bash
php artisan vendor:publish --tag=tap-config