Coder Social home page Coder Social logo

laravel-paymongo's Introduction

Paymongo for Laravel 6

Build Status Quality Score Latest Version on Packagist Total Downloads License

A PHP Library for Paymongo.

This package os 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 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=

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\LaravelPaymongo\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\LaravelPaymongo\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\LaravelPaymongo\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\LaravelPaymongo\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\LaravelPaymongo\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\LaravelPaymongo\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\LaravelPaymongo\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\LaravelPaymongo\Facades\Paymongo;

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

Enable or Disable Webhooks

Set the webhook enable or disable.

Sample

use Luigel\LaravelPaymongo\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\LaravelPaymongo\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 Rigel Kent Carbonel

laravel-paymongo's People

Contributors

rigelevotech avatar luigel avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.