Business-Stripe-WebCheckout
view release on metacpan or search on metacpan
lib/Business/Stripe/WebCheckout.pm view on Meta::CPAN
On success, returns the number of products in the Trolley
=head2 list_products
Returns an array contining the IDs of the products in the Trolley
=head2 get_product(id)
On success, returns a hash with the product details. Each key of the hash corresponds to items listed for B<add_product>
=head1 Checkout Methods
=head3 parameters
The C<get_intent>, C<get_intent_id>, C<get_ids> and C<checkout> methods all take the following optional parameters. See C<new> for their descriptions.
=over 4
=item *
C<reference>
=item *
C<email>
=back
=head2 get_intent
This method will not normally need calling.
Returns the full session intent from Stripe if successful or the Stripe error otherwise.
=head2 get_intent_id
Returns the intend_id that needs passing to the Stripe hosted checkout if successful or the Stripe error otherwise.
=head2 get_ids
In addition to the parameters listed above, this method also accepts the following optional parameters
=over 4
=item *
C<public-api> - See C<new>
=item *
C<format> - The format of the returned information. Current options are JSON or text. The default is text.
=back
Provides the Public Key and Intent Session ID as these are the two pieces of information required by the Javascript provided by Stripe and the Javacsript provided here. If text output is used (the default) the Public Key and Intent Session ID are pr...
=head2 checkout
A simple implementation of redirecting the user to the Stripe hosted checkout.
Calling this method provides a fully formed HTML document including the Content-Type header that can be sent to the users browser. The HTML document contains all the Javascript required to sent the user to the Stripe hosted checkout transparently. ...
=head1 EXAMPLES
=head2 1 - Using the Stripe provided Javascript
See L<https://stripe.com/docs/payments/accept-a-payment?integration=checkout>
=head3 Javascript
<html>
<head>
<title>Buy cool new product</title>
<script src="https://js.stripe.com/v3/"></script>
</head>
<body>
<button id="checkout-button">Checkout</button>
<script type="text/javascript">
// Create an instance of the Stripe object with your publishable API key
var stripe = Stripe('pk_test_00000000000000000000000000');
var checkoutButton = document.getElementById('checkout-button');
checkoutButton.addEventListener('click', function() {
// Create a new Checkout Session using the server-side endpoint you
// created in step 3.
fetch('https://example.com/cgi-bin/trolley.pl', {
method: 'POST',
})
.then(function(response) {
return response.json();
})
.then(function(session) {
return stripe.redirectToCheckout({ sessionId: session.id });
})
.then(function(result) {
// If `redirectToCheckout` fails due to a browser or network
// error, you should display the localized error message to your
// customer using `error.message`.
if (result.error) {
alert(result.error.message);
}
})
.catch(function(error) {
console.error('Error:', error);
});
});
</script>
</body>
</html>
=head3 Perl trolley.pl
use Business::Stripe::WebCheckout;
use strict;
my $stripe = Business::Stripe::WebCheckout->new(
'api-public' => 'pk_test_00000000000000000000000000',
'api-secret' => 'sk_test_00000000000000000000000000',
'success-url' => 'https://www.example.com/yippee.html',
'cancel-url' => 'https://www.example.com/ohdear.html',
( run in 0.611 second using v1.01-cache-2.11-cpan-5b529ec07f3 )