#!perl use 5.006; use strict; use warnings; use Test::More; use Business::Stripe::Webhook; plan tests => 7; *STDIN = *DATA; my $webhook_fail = Business::Stripe::Webhook->new( 'signing_secret' => 'whsec_...', 'invoice-paid' => \&pay_invoice, ); ok( !$webhook_fail->success, "Didn't instantiate" ); is( $webhook_fail->error, "Looks like this is not a web request!", "Not a web request" ); # Pretend we are on a webserver $ENV{'GATEWAY_INTERFACE'} = 'CGI/1.1'; $ENV{'CONTENT_LENGTH'} = 10024; $ENV{'HTTP_STRIPE_SIGNATURE'} = 't=ABCDEFGHIJ,v1=abcdefghij'; my $webhook_pass1 = Business::Stripe::Webhook->new( 'invoice-paid' => \&pay_invoice, ); ok( $webhook_pass1->success, "Basic instantiation" ); $webhook_pass1->process(); my $webhook_fail2 = Business::Stripe::Webhook->new( signing_secret => 'whsec_...', 'invoice-paid' => \&pay_invoice, ); is( $webhook_fail2->error, 'No payload data', "No payload for signed instantiation" ); $webhook_fail2->process(); ok( !$webhook_fail2->success, "Signature error" ); is( $webhook_fail2->error, 'Invalid Stripe Signature', "Invalid signature" ); sub pay_invoice { is( $_[0]->{'object'}, 'event', "pay.invoice handled" ); } __DATA__ { "id": "evt_1NFK32EfkkexSbWLZb6LoEap", "object": "event", "api_version": "2020-08-27", "data": { "object": { "id": "in_1NFK30EfkkfpSbWLeMoI8HzB", } } }