Business-GoCardless

 view release on metacpan or  search on metacpan

lib/Business/GoCardless/Webhook/Event.pm  view on Meta::CPAN

package Business::GoCardless::Webhook::Event;

=head1 NAME

Business::GoCardless::Webhook::Event

=head1 DESCRIPTION

A class for gocardless webhook events, extends L<Business::GoCardless::Resource>.
For more details see the gocardless API documentation specific to webhooks:
https://developer.gocardless.com/api-reference/#appendix-webhooks

=cut

use strict;
use warnings;

use Moo;
extends 'Business::GoCardless::Resource';
with 'Business::GoCardless::Utils';

use Business::GoCardless::Exception;
use Business::GoCardless::Payment;
use Business::GoCardless::Subscription;
use Business::GoCardless::Mandate;
use Business::GoCardless::Payout;
use Business::GoCardless::Refund;
use Business::GoCardless::Customer;
use Business::GoCardless::BillingRequest;
use Business::GoCardless::Creditor;
use Business::GoCardless::InstalmentSchedule;
use Business::GoCardless::OutboundPayment;
use Business::GoCardless::SchemeIdentifier;
use Business::GoCardless::PaymentAccountTransaction;

=head1 ATTRIBUTES

    id
    created_at
    action
    resource_type
    links
    details
    metadata
    resource_metadata
    customer_notifications
    source

This class is used for events in webhooks, and for events from the events API
endpoints (see L<Business::GoCardless::Pro/events>).

=cut

has [ qw/
    id
    created_at
    action
    resource_type
    links
/ ] => (
    is       => 'ro',
	required => 1,
);

has [ qw/
    details
    metadata
    resource_metadata
    customer_notifications
    source
/ ] => (
    is       => 'rw',
	required => 0,
);

=head2 resources

Returns an array of resource objects (Payment, Subscription, etc) that are present
in the event allowing you to do things with them or update your own data:

    if ( $Event->is_payment ) {

        foreach my $Payment ( $Event->resources ) {

            if ( $Event->action eq 'paid_out' ) {
                ...
            }
        }
    }

=cut

sub resources {
	my ( $self ) = @_;

	return if ! $self->resource_type;

	my $mapping = {
		payments      => 'payment',
		payouts       => 'payout',
		subscriptions => 'subscription',
		mandates      => 'mandate',
		refunds       => 'refund',
		customers     => 'customer',
		billing_requests             => 'billing_request',
		creditors                    => 'creditor',
		instalment_schedules         => 'instalment_schedule',
		outbound_payments            => 'outbound_payment',
		scheme_identifiers           => 'scheme_identifier',
		payment_account_transactions => 'payment_account_transaction',



( run in 2.042 seconds using v1.01-cache-2.11-cpan-99fa8243a42 )