Skip to content

harlekoy/paymongo

Repository files navigation

Paymongo for Laravel

Build Status Quality Score Latest Version on Packagist Total Downloads License

A PHP Library for Paymongo.

This package is not affiliated with Paymongo. The package requires PHP 7.2+

Installation

You can install the package via composer:

composer require luigel/laravel-paymongo

Laravel 6 and up uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.

Put your Secret Key and Public Key in you .env file.

PAYMONGO_SECRET_KEY=
PAYMONGO_PUBLIC_KEY=

Compatibility and Supported Versions

Laravel-Paymongo supports Laravel 6.* and 7.*

Usage

Tokens

Create Token

Creates a one-time use token representing your customer's credit card details. NOTE: This token can only be used once to create a Payment. You must create separate tokens for every payment attempt.

Sample

use Luigel\Paymongo\Facades\Paymongo;

$token = Paymongo::token()->create([
    'number' => '4242424242424242',
    'exp_month' => 12,
    'exp_year' => 25,
    'cvc' => "123",
]);

Get Token

Retrieve a token given an ID. The prefix for the id is tok_ followed by a unique hash representing the token. Just pass the token id to find($id) method.

Sample

use Luigel\Paymongo\Facades\Paymongo;

$token = Paymongo::token()->find($tokenId);

Payments

Create Payment

To charge a payment source, you must create a Payment object. When in test mode, your payment sources won't actually be charged. You can select specific payment sources for different success and failure scenarios.

Payload

Refer to Paymongo documentation for payload guidelines.

Sample

use Luigel\Paymongo\Facades\Paymongo;

$payment = Paymongo::payment()->create([
    'amount' => 100.00,
    'currency' => 'PHP',
    'description' => 'A testing Payment',
    'statement_descriptor' => 'LUIGEL STORE',
    'source' => [
        'id' => 'tok_Jt7WJhH4eQaEEZqWxdXW3sz5',
        'type' => 'token'
    ]
]);

Get Payment

You can retrieve a Payment by providing a payment ID. The prefix for the id is pay_ followed by a unique hash representing the payment. Just pass the payment id to find($paymentId) method.

Sample

use Luigel\Paymongo\Facades\Paymongo;

$payment = Paymongo::payment()->find('pay_i35wBzLNdX8i9nKEPaSKWGib');

Get all Payments

Returns all the payments you previously created, with the most recent payments returned first. Currently, all payments are returned as one batch. We will be introducing pagination and limits in the next iteration of the API.

Sample

use Luigel\Paymongo\Facades\Paymongo;

$payments = Paymongo::payment()->all();

Sources

Create Source

Creates a source to let the user pay using their Gcash Accounts.

Payload

Refer to Paymongo documentation for payload guidelines.

Sample

use Luigel\Paymongo\Facades\Paymongo;

$source = Paymongo::source()->create([
    'type' => 'gcash',
    'amount' => 100.00,
    'currency' => 'PHP',
    'redirect' => [
        'success' => 'https://your-domain.com/success',
        'failed' => 'https://your-domain.com/failed'
    ]
]);

Webhooks

Create Webhook

Creates a webhook.

Payload

Refer to Paymongo documentation for payload guidelines.

Sample

use Luigel\Paymongo\Facades\Paymongo;

$webhook = Paymongo::webhook()->create([
    'url' => 'http://your-domain/webhook/source-chargeable',
    'events' => [
        'source.chargeable'
    ]
]);

List all Webhooks

Returns all the webhooks you previously created, with the most recent webhooks returned first.

Sample

use Luigel\Paymongo\Facades\Paymongo;

$webhook = Paymongo::webhook()->all();

Enable or Disable Webhooks

Set the webhook enable or disable.

Sample

use Luigel\Paymongo\Facades\Paymongo;
// Enable webhook
$webhook = Paymongo::webhook()->find('hook_9VrvpRkkYqK6twbhuvcVTtjM')->enable();

// Disable webhook
$webhook = Paymongo::webhook()->find('hook_9VrvpRkkYqK6twbhuvcVTtjM')->disable();

Update Webhook

Updates a specific webhook

Sample

use Luigel\Paymongo\Facades\Paymongo;

$webhook = Paymongo::webhook()->find('hook_9VrvpRkkYqK6twbhuvcVTtjM')->update([
    'url' => 'https://update-domain.com/webhook'
]);

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Made with ❤️ by Harlequin Doyon

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages