Laravel PayMongo

Classic Links

Classic Links are PayMongo's original payment links API: a PayMongo-hosted payment page for one amount, at a URL you share with the customer. The package still supports them, on Paymongo::links().

For new integrations, use Payment Links instead. PayMongo has announced that it will deprecate the Classic Links API and recommends moving existing integrations to Payment Links; see its migration guide.

A single link comes back as a Link.

Classic Links, links() Payment Links, paymentLinks()
Shareable URL $link->checkoutUrl $link->url
status Whether it was paid: Unpaid, Paid, or Archived Whether it takes payments: Active or Archived
Payments On the link, as $link->payments Fetched with payments()
Limit how many times it is paid No restriction.completed_sessions.limit
metadata No Yes

create() takes the amount in integer centavos and a description. Send the customer the checkoutUrl it returns:

use Luigel\Paymongo\Facades\Paymongo;

$link = Paymongo::links()->create([
    'amount' => 150050, // PHP 1,500.50, in centavos
    'description' => 'Invoice INV-1234',
    'remarks' => 'Custom order via Messenger',
]);

$link->checkoutUrl;     // send this to your customer
$link->referenceNumber; // e.g. "WTmSJbV"

retrieve() finds a link by its id. retrieveByReference() finds it by the short reference number at the end of its URL, and returns null when no link has that reference:

use Luigel\Paymongo\Facades\Paymongo;

$link = Paymongo::links()->retrieve('link_wWaibr22CzEnficNhQNPUdoo');

$link->status; // ?LinkStatus: Unpaid, Paid or Archived

foreach ($link->payments as $payment) {
    $payment->id; // "pay_..."
}

$linkByReference = Paymongo::links()->retrieveByReference('WTmSJbV'); // null when no link has it

list() returns a CursorPage of links. Iterate it, or call lazy() to walk every page:

use Luigel\Paymongo\Facades\Paymongo;

foreach (Paymongo::links()->list(['limit' => 20]) as $link) {
    $link->description;
    $link->money()?->format(); // "₱1,500.50"
}

archive() stops a link from being paid, and unarchive() opens it again:

use Luigel\Paymongo\Facades\Paymongo;

$link = Paymongo::links()->archive('link_wWaibr22CzEnficNhQNPUdoo');   // can no longer be paid
$link = Paymongo::links()->unarchive('link_wWaibr22CzEnficNhQNPUdoo'); // can be paid again

Know when it was paid

PayMongo sends link.payment.paid when a customer pays a link, and the package dispatches it as Luigel\Paymongo\Events\LinkPaymentPaid. See Webhooks.