Payments

Payment intents

A payment intent tracks one attempt to collect money, from creation through a payment method being attached to a final succeeded or cancelled state. Amounts are integer centavos: 10000 is ₱100.00.

Read the Payment Intents docs

Every demonstration here makes a real PayMongo API call in test mode. Nothing is simulated, and no real money moves.

Create payment intent

Create an intent for an amount and the payment methods it accepts.

PHP
use Luigel\Paymongo\Facades\Paymongo;

$paymentIntent = Paymongo::paymentIntents()->create(
    attributes: [
        'amount' => 10000,
        'currency' => 'PHP',
        'payment_method_allowed' => [
            'card',
            'gcash',
            'paymaya',
        ],
        'description' => 'Laravel PayMongo Playground demo',
        'statement_descriptor' => 'PAYMONGO PLAYGROUND',
        'capture_type' => 'automatic',
    ],
);

Create a hold (manual capture)

Create a card-only intent with capture type manual. Attaching a card then holds the amount until you capture or cancel.

Test mode: Capture needs an intent created with capture type manual, as the hold Step does, and a card attached, so it reaches awaiting_capture. PayMongo enables hold then capture only on request, for Visa and Mastercard on eligible accounts; without it PayMongo rejects the request and the error shows here.

PHP
use Luigel\Paymongo\Facades\Paymongo;

$paymentIntent = Paymongo::paymentIntents()->create(
    attributes: [
        'amount' => 10000,
        'currency' => 'PHP',
        'payment_method_allowed' => [
            'card',
        ],
        'description' => 'Laravel PayMongo Playground demo',
        'statement_descriptor' => 'PAYMONGO PLAYGROUND',
        'capture_type' => 'manual',
    ],
);

Create card payment method

Create a card payment method to attach. Every supported type is in the Payment methods scenario.

PHP
use Luigel\Paymongo\Facades\Paymongo;

$paymentMethod = Paymongo::paymentMethods()->create(
    attributes: [
        'type' => 'card',
        'details' => [
            'card_number' => '••••4345',
            'exp_month' => '••',
            'exp_year' => '••',
            'cvc' => '•••',
        ],
        'billing' => [
            'name' => '••••',
            'email' => '••••',
            'phone' => '••••',
        ],
    ],
);

Attach payment method

Attach a payment method to an intent to attempt the payment. E-wallets and other redirect methods need a return URL.

Test mode: A 3D Secure card or a redirect method leaves the intent in awaiting_next_action with a redirect URL. Open it to choose Authorize or Fail on the PayMongo test page, then retrieve the intent. The default card needs no 3D Secure.

PHP
use Luigel\Paymongo\Facades\Paymongo;

$paymentIntent = Paymongo::paymentIntents()->attach(
    id: '{payment_intent id}',
    paymentMethodId: '{payment_method id}',
    returnUrl: 'https://paymongo.rigelkentcarbonel.com/playground/scenarios/payment-intents',
);

Retrieve payment intent

Fetch the current state of a payment intent created in the Playground.

PHP
use Luigel\Paymongo\Facades\Paymongo;

$paymentIntent = Paymongo::paymentIntents()->retrieve(
    id: '{payment_intent id}',
);

Retrieve with the client key

Fetch a payment intent the way a browser does: with the public key and the intent's client key instead of the secret key. Your checkout page uses this to poll an intent without holding the secret key.

Test mode: The Playground masks client keys, so it reads the intent's client key on the server with the secret key first; in your app it comes from the intent you created. PAYMONGO_PUBLIC_KEY must be set.

PHP
use Luigel\Paymongo\Facades\Paymongo;

$paymentIntent = Paymongo::paymentIntents()->retrieveUsingClientKey(
    id: '{payment_intent id}',
    clientKey: '{client key}',
);

Capture the full amount

Charge a held card payment in full by capturing without an amount.

Test mode: Capture needs an intent created with capture type manual, as the hold Step does, and a card attached, so it reaches awaiting_capture. PayMongo enables hold then capture only on request, for Visa and Mastercard on eligible accounts; without it PayMongo rejects the request and the error shows here.

PHP
use Luigel\Paymongo\Facades\Paymongo;

$paymentIntent = Paymongo::paymentIntents()->capture(
    id: '{payment_intent id}',
);

Capture part of the amount

Charge less than the held amount. Capturing more than the intent amount fails with allowed_amount_exceeded.

Test mode: Capture needs an intent created with capture type manual, as the hold Step does, and a card attached, so it reaches awaiting_capture. PayMongo enables hold then capture only on request, for Visa and Mastercard on eligible accounts; without it PayMongo rejects the request and the error shows here.

PHP
use Luigel\Paymongo\Facades\Paymongo;

$paymentIntent = Paymongo::paymentIntents()->capture(
    id: '{payment_intent id}',
    amount: 5000,
);

Cancel payment intent

Cancel an intent so it can no longer be paid, or void a held card payment instead of capturing it.

PHP
use Luigel\Paymongo\Facades\Paymongo;

$paymentIntent = Paymongo::paymentIntents()->cancel(
    id: '{payment_intent id}',
);

Create a card that declines

Create a card payment method with a PayMongo test card that declines, then attach it to see how the package surfaces the decline.

Test mode: PayMongo accepts the card here and declines it on attach. Its docs do not say whether the decline comes back as an HTTP error, which the package throws as PaymentDeclinedException for HTTP 402, or as the intent returning to awaiting_payment_method with a last payment error. The Playground shows whichever PayMongo returns.

PHP
use Luigel\Paymongo\Facades\Paymongo;

$paymentMethod = Paymongo::paymentMethods()->create(
    attributes: [
        'type' => 'card',
        'details' => [
            'card_number' => '••••1111',
            'exp_month' => '••',
            'exp_year' => '••',
            'cvc' => '•••',
        ],
        'billing' => [
            'name' => '••••',
            'email' => '••••',
            'phone' => '••••',
        ],
    ],
);

Create an intent below the minimum amount

Send an amount under the ₱20.00 minimum to see how the package surfaces an invalid input.

PHP
use Luigel\Paymongo\Facades\Paymongo;

$paymentIntent = Paymongo::paymentIntents()->create(
    attributes: [
        'amount' => 100,
        'currency' => 'PHP',
        'payment_method_allowed' => [
            'card',
            'gcash',
            'paymaya',
        ],
        'description' => 'Laravel PayMongo Playground demo',
        'statement_descriptor' => 'PAYMONGO PLAYGROUND',
        'capture_type' => 'automatic',
    ],
);