Business-Stripe-Webhook

 view release on metacpan or  search on metacpan

lib/Business/Stripe/Webhook.pm  view on Meta::CPAN

  );

This method takes one or more parameters:

=over

=item *

B<signing_secret>: The webhook signing secret provided by Stripe. If omitted, the Stripe Signature will not be checked.

=item *

B<payload>: A JSON string.  Required (I<see below>). The JSON object from Stripe.

=item *

B<api_secret>: The Stripe secret API Key - see L<https://stripe.com/docs/keys>. Optional but will be required if the C<get_subscription> method is needed.

=item *

B<I<stripe-event>>: One or more callbacks to the subroutines to handle the webhooks events sent by Stripe.  See L<https://stripe.com/docs/api/events/list>.

To listen for an event, change the fullstop in the Stripe event name to a minus sign and use that as the parameter.  The events you define should match the events you ask Stripe to send.  Any events Stripe sends that do not have a callback defined wi...

Stripe event C<invoice.paid> becomes C<invoice-paid>
Stripe event C<invoice.payment_failed> becomes C<invoice-payment_failed>

=item *

B<all-webhooks>: A callback subroutine which will be called for every event received from Stripe even if a callback subroutine for that event has not been defined.

=item *

B<error>: A callback subroutine to handle errors.  If not defined, errors are sent to C<STDERR>.

=item *

B<warning>: A callback subroutine to handle warnings.  If not defined, warnings are sent to C<STDERR>.  If set to C<nowarn>, warnings are ignored.


=back

Previous versions on L<Business::Stripe::Webhook> allowed the B<payload> parameter to be omitted.  In this case, the module would read C<STDIN> to obtain the JSON string.  This continues to work for backward compatibility only but will be removed fro...

=head2 success

Returns true if the last operation was successful, or false otherwise.

  if ($webhook->success()) {
      ...
  }

=head2 error

Returns the error message from the last operation, or an empty string if there was no error.

  my $error = $webhook->error();

=head2 process

This method processes the webhook sent from Stripe.  It checks the Stripe Signature if a C<signing_secret> parameter has been included and calls the defined subroutine to handle the Stripe event.  Each subroutine is passed a JSON decoded Event Object...

  my $result = $webhook->process();

This method takes no parameters.

Normally, the return value can be ignored.  Returns C<undef> if there was an error or warning.

If the C<v1> parameter is missing an C<error> is set and the method returns C<undef>.  Otherwise it returns true if the signature has been verified or false if not.

=head2 check_signature

Checks the signature of the webhook to verify that it was sent by Stripe.

  my $sig_ok = $webhook->check_signature();

This method takes no parameters.

Normally, this method does not need to be called.  It is called by the C<process> method if a C<signing_secret> parameter was included when the object was created.

=head2 reply

Sends a reply to Stripe.

  print $webhook->reply(status => 'OK');

It takes one or more optional parameters.

Parameters passed to this method are then passed through to Stripe.  These are available in the Stripe Dashboard and are especially useful for troubleshooting during development.

The following parameters are always passed to Stripe:

=over

=item *

B<status>: C<noaction> if the event did not have a handler, C<success> if the event was handled or C<failed> if it wasn't

=item *

B<sent_to>: An array containing the names of the callback subroutines that handled the event.

=item *

B<sent_to_all>: C<true> or C<false> to indicate if the C<all-webhooks> parameter was set

=item *

B<timestamp>: The server time at which the webhook was handled

=back

=head2 get_subscription

Retrieves a subscription object from Stripe.  This is required to retrieve information such as the end of the current subscription period or whether the subscription is set to cancel after the current period.

  my $response = $webhook->get_subscription($subscription_id, $secret_key);

This method takes two parameters:

=over



( run in 0.769 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )