PHP code example of mongosprout / paymongo-bridge

1. Go to this page and download the library: Download mongosprout/paymongo-bridge 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/ */

    

mongosprout / paymongo-bridge example snippets


use MongoSprout\PayMongo\Facades\PayMongo;
use MongoSprout\PayMongo\Money;

$customer = PayMongo::customers()->create([
    'first_name' => 'Maria', 'last_name' => 'Santos',
    'email' => '[email protected]', 'phone' => '+639171234567',
]);

// Hosted checkout, for the wallets that cannot be auto debited.
$session = PayMongo::checkoutSessions()->create([
    'line_items' => [[
        'name' => 'Business plan',
        'amount' => Money::ofMajor('2000.00')->toCentavos(),
        'currency' => 'PHP',
        'quantity' => 1,
    ]],
    'payment_method_types' => ['gcash', 'card', 'paymaya', 'grab_pay'],
    'reference_number' => $invoice->number,
    'metadata' => ['invoice_id' => (string) $invoice->id],
    'success_url' => route('billing.return', $invoice),
    'cancel_url' => route('billing.cancel', $invoice),
]);

return redirect($session->attr('checkout_url'));

PayMongo::paymentMethods()->attachToCustomer($customerId, $paymentMethodId);
PayMongo::subscriptions()->create($customerId, $planId, ['invoice_id' => (string) $invoice->id]);

use MongoSprout\PayMongo\Webhooks\Events\SubscriptionInvoicePaid;

class GrantAccess
{
    public function handle(SubscriptionInvoicePaid $event): void
    {
        $invoice = Invoice::find($event->metadata('invoice_id'));

        // Handlers must be safe to run twice. PayMongo redelivers.
        $invoice?->markPaid($event->resource()->centavos());
    }
}

$transfers = PayMongo::transfers();

$transfers->createBatch([
    $transfers->transfer(
        sourceNumber: config('paymongo.disbursements.source_account_number'),
        sourceName: config('paymongo.disbursements.source_account_name'),
        destinationNumber: $employee->ewallet_number,
        destinationName: $employee->full_name,
        destinationBic: 'GXCHPHM2',
        amount: Money::ofMajor($item->net_pay),
        referenceNumber: $item->reference_number,
    ),
]);

Money::ofMajor('1500.15')->toCentavos();   // 150015
Money::ofCentavos(150015)->toMajor();      // "1500.15"  safe for a decimal column

$this->fakePayMongo();

$this->paymongoWebhook('subscription.invoice.paid', metadata: ['invoice_id' => '7'])->assertOk();
bash
php artisan paymongo:webhook:register https://your-app.test/paymongo/webhook