Giter Club home page Giter Club logo

gocardless-laravel's Introduction

gocardless-laravel

Build Status Scrutinizer Code Quality Latest Stable Version Latest Unstable Version License

GoCardless Pro PHP Client package integration for Laravel.

This package tries to provide an easy, scalable and maintainable way to integrate Gocardless into your laravel project.

It provides a Facade that wraps the Gocardless PHP client and also an easy way to handle the webhooks that Gocardless sends. This is done following the steps that Spatie uses for their Stripe Laravel Webhooks package.

Installation

Get the package with composer:

composer require nestednet/gocardless-laravel

1. If you are using Laravel >5.5 the package will be autodiscobered, for older versions add the service provider at your config/app.php file.

2. Publish the configuration file

$ php artisan vendor:publish --provider="Nestednet\Gocardless\GocardlessServiceProvider"

This will publish both the configuration file and the migration file.

3. Review the configuration file

config/gocardless.php

and add your Gocardless API token and environment to the .env file.

4. After publishing the migration you can run the migration and create the gocardless_webhooks_table

5. The package provides a Macro route (gocardlessWebhooks). You can create a route at your routes file of your app. This route will be the endpoint where Gocardless will send the webhooks, you should register this webhook endpoint at your Gocardless dashboard.

Route::gocardlessWebhooks('gocardless-webhook-endpoint');

This will register a POST route to a the controller provided by this package. You should add the route to the except array of the VerifyCsrfToken middleware.

protected $except = [
    'gocardless-webhook-endpoint',
];
Usage

Once the package is properly installed you can use the Gocardless facade to access the methods of the Gocardless PHP client. The documentation of this methods can be found here: Gocardless PHP cleint documentation

If you use Gocardless at your project you provably will use webhooks to handle the asynchronous payment states. This package provides an easy way to handle the webhooks.

Gocardless will send you webhooks with events. This events will contain the updates of your Gocardless resources.

This package will verify the signature of the requests and if it's valid. Unless something goes terribly wrong, and even if one of the events inside the webhook fails the controller will reposnd with a 200 to Gocardless. This prevents Gocardless from spamming retries to the endpoint.

If an event fails to be processed the exception will be saved to the database into the gocardless_webhook_calls table, you can find the failed events there.

This package provides two ways to handle the webhook requests:

  • Using jobs
  • Using events
Using jobs

You can find a jobs array inside the config\gocardless.php.

You can register any job that you want to the gocardless events. An event from Gocardless references one resource resource_type and one action. In order to register a job to an action you should add it with the key {resource_type}_{action}.

'jobs' => [
 // '{resource_type}_{action} => path/to/job::class,
    'payments_created' => App\Jobs\PaymentConfirmed::class,
]

In order to avoid timeouts it's highly recommended to use queued jobs.

Using events

Every time an event is processed by the package it will trigger an event with this structure:

gocardless-webhooks::{resource_type}_{action}

The payload of the event will be the GocardlessWebhookCall (or an extended model) instance created with the request.

You can register listeners to this events in the EventServiceProvider:

/**
 * The event listener mappings for the application.
 *
 * @var array
 */
protected $listen = [
    'gocardless-webhooks::payments_created' => [
        App\Listeners\ListenerOfPaymentsCreated::class,
    ],
];

gocardless-laravel's People

Contributors

eaarranz avatar scrutinizer-auto-fixer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

gocardless-laravel's Issues

Update package

Hi,

Awesome package by the way, however can it be updated to work with "gocardless/gocardless-pro": "^4.0", ?

Thanks.

Extend the package to handle the Gocardless webhooks.

Gocardless relies heavily on webhooks to provide updates of the payments, mandates and other resources. A good package Laravel for Gocardless should provide a way to handle them.

  • Add a middleware to verify the webhooks signatures. 61add26
  • Add a controller to handle the webhook requests. 8e679bb
  • Provide a webhook model to encapsulate the logic. 8e679bb & 3dc4675
  • Dynamically bind jobs to the different events that the end users need to control (using the config file).
  • In order to help with the use and maintainability of the package create a WebhookFailed exception. 8e679bb

Trying to get property of non-object in remove customer BaseService.php

Hi all

Thank you first for this helpful package the make life easier to deal with gocardless.

I just tried to remove a customer using the remove method like this:
$cliene->customers()->remove('CUXXXXXXX')

I got this error
Trying to get property of non-object vendor/gocardless/gocardless-pro/lib/Services/BaseService.php:86 vendor/gocardless/gocardless-pro/lib/Services/BaseService.php(65): GoCardlessPro\\Services\\BaseService->getUnenvelopedBody(NULL) gocardless/gocardless-pro/lib/Services/CustomersService.php(171)

I think the issue is the remove customer request is performed as DELETE, and the response from the api is null but in BaseService.php line 86 it's decoded the response to json but the response here is null.

The package version is "nestednet/gocardless-laravel": "^0.2.0"

Thank you

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.