Laravel PayMongo

Payment Methods

A Payment Method is what the customer pays with: a card, an e-wallet, online banking, QR Ph, or buy now, pay later, along with their billing details. On its own it charges nothing. Attach it to a payment intent to make the payment.

Every method lives on Paymongo::paymentMethods() and returns a PaymentMethod. For every attribute PayMongo accepts, see its Payment Method reference.

Create a card payment method

create() takes the method's type, its details, and optional billing:

use Luigel\Paymongo\Facades\Paymongo;

$method = Paymongo::paymentMethods()->create([
    'type' => 'card',
    'details' => [
        'card_number' => '4343434343434345', // a test card
        'exp_month' => 12,
        'exp_year' => 34,
        'cvc' => '123',
    ],
    'billing' => [
        'name' => 'Juan dela Cruz',
        'email' => 'juan@example.com',
        'phone' => '+639171234567',
        'address' => [
            'line1' => '123 Osmeña Blvd',
            'city' => 'Cebu City',
            'state' => 'Cebu',
            'postal_code' => '6000',
            'country' => 'PH',
        ],
    ],
]);

$method->id; // "pm_...", to attach to a payment intent

In production, do not create card payment methods on your server. Create them in the browser with your public key, so card numbers never reach your server and you stay out of PCI DSS scope, then send the resulting pm_... id to your server to attach. The example above uses a test card, and is how your tests and scripts can create one.

Create an e-wallet, bank, or QR Ph payment method

Every other type needs only its type. The customer authorizes the payment on the provider's page, or by scanning a code, after you attach it:

use Luigel\Paymongo\Enums\PaymentMethodType;
use Luigel\Paymongo\Facades\Paymongo;

$gcash = Paymongo::paymentMethods()->create(['type' => PaymentMethodType::Gcash]);

$qrph = Paymongo::paymentMethods()->create([
    'type' => 'qrph',
    'expiry_seconds' => 900, // the QR code expires 15 minutes after it is attached
]);

type takes a Luigel\Paymongo\Enums\PaymentMethodType case or its string value:

Case Value Pays with
Card card Credit or debit card
Gcash gcash GCash
Paymaya paymaya Maya
GrabPay grab_pay GrabPay
ShopeePay shopee_pay ShopeePay
Qrph qrph Any bank or e-wallet app that scans QR Ph
Dob dob Direct online banking
Brankas brankas Online banking through Brankas
Billease billease BillEase, buy now, pay later
Atome atome Atome, buy now, pay later

expiry_seconds sets how long a qrph or shopee_pay method can be paid once attached, from 60 to 9000 seconds for QR Ph.

Retrieve a payment method

retrieve() returns the method with typed billing details. $method->methodType holds the type:

use Luigel\Paymongo\Facades\Paymongo;

$method = Paymongo::paymentMethods()->retrieve('pm_wr98R2gwWroVxfkcNVZBuXg2');

$method->methodType;               // ?PaymentMethodType: Card, Gcash, ...
$method->billing?->name;           // "Juan dela Cruz"
$method->billing?->address?->city; // "Cebu City"
$method->details;                  // ?array, e.g. the card's last4 and exp_month; never the full number