NAME

Net::API::Stripe::WebHook::Apache - An Apache handler for Stripe Web Hook

SYNOPSIS

VERSION

0.1

DESCRIPTION

This is the module to handle Stripe Web Hooks using Apache/mod_perl configuration

CONFIGURATION

Your Apache VirtualHost configuration would look something like this:

    <VirtualHost *:443>
    	ServerName example.com:443
        ServerAdmin www@example.com
        DocumentRoot /home/john/example.com
        DirectoryIndex "index.html" "index.php"
        CustomLog "${APACHE_LOG_DIR}/example.com-access.log" combined
        ErrorLog "${APACHE_LOG_DIR}/example.com-error.log"
        LogLevel warn
        <Directory "/home/john/example.com">
            Options All +MultiViews -ExecCGI -Indexes +Includes +FollowSymLinks
            AllowOverride All
        </Directory>
        ScriptAlias "/cgi-bin/"     "/home/john/example.com/cgi-bin/"
        <Directory "/home/john/example.com/cgi-bin/">
            Options All +Includes +ExecCGI -Indexes -MultiViews
            AllowOverride All
            SetHandler cgi-script
            AcceptPathInfo On
	        Require all granted
        </Directory>
        <IfModule mod_perl.c>
			PerlOptions		+GlobalRequest
			PerlPassEnv		MOD_PERL
			PerlPassEnv		PATH_INFO
			PerlModule		Apache2::Request
			<Perl>
			unshift( @INC, "/home/john/lib" );
			</Perl>
			<Location /hook>
				SetHandler		perl-script
				## Switch it back to modperl once the soft is stable
				# SetHandler		modperl
				PerlSendHeader		On
				PerlSetupEnv		On
				PerlOptions			+GlobalRequest
				PerlResponseHandler	Net::API::Stripe::WebHook::Apache
				Options 			+ExecCGI
				Order allow,deny
				Allow from all
			</Location>
        </IfModule>

        SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf
        SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem
    </Virtualhost>

The key part is the line with PerlResponseHandler and value Net::API::Stripe::WebHook::Apache. This will tell Apache/mod_perl that our module will handle all http request for this particular location.

So, if we get an incoming event from Stripe at https://example.com/hook/d18bbab7-e537-4dba-9a1f-dd6cc70ea6c1, we receive d18bbab7-e537-4dba-9a1f-dd6cc70ea6c1 as part of the path info, and we call validate_webhook() to validate it before processing the event incoming packet.

Apache will call our special method handler(), which will invoque validate_webhook() that should be overriden by your module, and which must return either true or false. Upon successful return from validate_webhook(), handler will create a new constructor such as $class->new()

What you want to do is inherit Net::API::Stripe::WebHook::Apache and set your own module in Apache configuration, like so:

PerlResponseHandler My::WebHookHandler

The inherited handler will be called by Apache with the class My::WebHookHandler and the apache Apache2::RequestRec object. As we wrote above, once validated, handler will initiate an object from your module by calling My::WebHookHandler-new( object => Net::API::Stripe::Event, request => Net::API::REST::Request, response => Net::API::REST::Response )> where each package name are an object. object represents the event packet received from Stripe. request is an object to access great number of method to access the Apache API, and response is an object to access Apache API to provide a reply. See the manual page for each of those package.

CONSTRUCTOR

new( %args )

Creates a new Net::API::Stripe::WebHook::Apache objects. This should be overriden by your own package.

object Net::API::Stripe::Event object
request Net::API::REST::Request
request Net::API::REST::Response
handler( $class, $r )

This is called by Apache/mod_perl upon incoming http request

verbose

Toggles verbose mode on/off

debug

Toggles debug mode on/off

METHODS

API SAMPLE

{
  "object": "balance",
  "available": [
	{
	  "amount": 0,
	  "currency": "jpy",
	  "source_types": {
		"card": 0
	  }
	}
  ],
  "connect_reserved": [
	{
	  "amount": 0,
	  "currency": "jpy"
	}
  ],
  "livemode": false,
  "pending": [
	{
	  "amount": 7712,
	  "currency": "jpy",
	  "source_types": {
		"card": 7712
	  }
	}
  ]
}

HISTORY

v0.1

Initial version

AUTHOR

Jacques Deguest <jack@deguest.jp>

SEE ALSO

Stripe API documentation:

https://stripe.com/docs/api

COPYRIGHT & LICENSE

Copyright (c) 2018-2019 DEGUEST Pte. Ltd.

You can use, copy, modify and redistribute this package and associated files under the same terms as Perl itself.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 296:

You forgot a '=back' before '=head1'