PHP code example of programmatordev / kirby-stripe-checkout
1. Go to this page and download the library: Download programmatordev/kirby-stripe-checkout library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
programmatordev / kirby-stripe-checkout example snippets
// site/config/config.php
return [
'programmatordev.stripe-checkout.translations' => [
'translations' => [
// The German translation is not currently bundled with the plugin, so you can provide your own
'de' => [
'stripe-checkout.fields.product.price.label' => 'Preis',
'stripe-checkout.fields.product.thumbnail.label' => 'Vorschaubild',
'stripe-checkout.fields.settings.shippingHeadline.label' => 'Versand',
'stripe-checkout.fields.settings.shippingEnabled.label' => 'Versandeinstellungen',
'stripe-checkout.fields.settings.shippingAllowedCountries.label' => 'Erlaubte Länder',
// ...
]
]
]
];
// config.php
return [
'hooks' => [
'stripe-checkout.session.create:before' => function (array $sessionParams): array
{
// for example, if you want to enable promotion codes
// https://docs.stripe.com/api/checkout/sessions/create?lang=php#create_checkout_session-allow_promotion_codes
$sessionParams['allow_promotion_codes'] = true;
return $sessionParams;
}
]
];
// config.php
use Stripe\Checkout\Session;
use Stripe\Event;
return [
'hooks' => [
'stripe-checkout.order.create:before' => function (array $orderContent, Session $checkoutSession, Event $stripeEvent): array
{
// change order content
// ...
return $orderContent;
}
]
];
// config.php
use Kirby\Cms\Page;
use Stripe\Checkout\Session;
use Stripe\Event;
return [
'hooks' => [
'stripe-checkout.payment:succeeded' => function (Page $orderPage, Session $checkoutSession, Event $stripeEvent): void
{
// email the customer when the payment succeeds
kirby()->email([
'from' => '[email protected]',
'to' => $orderPage->customer()->toObject()->email()->value(),
'subject' => 'Thank you for your order!',
'body' => 'Your order will be processed soon.',
]);
}
]
];
// config.php
use Kirby\Cms\Page;
use Stripe\Checkout\Session;
use Stripe\Event;
return [
'hooks' => [
'stripe-checkout.payment:pending' => function (Page $orderPage, Session $checkoutSession, Event $stripeEvent): void
{
// email the customer when the payment is pending
kirby()->email([
'from' => '[email protected]',
'to' => $orderPage->customer()->toObject()->email()->value(),
'subject' => 'Thank you for your order!',
'body' => 'Your order is pending payment.',
]);
}
]
];
// config.php
use Kirby\Cms\Page;
use Stripe\Checkout\Session;
use Stripe\Event;
return [
'hooks' => [
'stripe-checkout.payment:failed' => function (Page $orderPage, Session $checkoutSession, Event $stripeEvent): void
{
// email the customer when the payment has failed
kirby()->email([
'from' => '[email protected]',
'to' => $orderPage->customer()->toObject()->email()->value(),
'subject' => 'Bad news!',
'body' => 'Your order has been canceled because the payment has failed.',
]);
}
]
];
use ProgrammatorDev\StripeCheckout\Cart\Cart;
cart(array $options = []): Cart
cart([
// the same as configured in the plugin options
'currency' => option('programmatordev.stripe-checkout.currency'),
'cartSnippet' => option('programmatordev.stripe-checkout.cartSnippet')
]);
addItem(string $id, int $quantity, ?array $options = null): string
$cart = cart();
// a key is returned and uniquely identifies that item in the cart
$key = $cart->addItem(id: 'products/cd', quantity: 1);
// you can add options per item
$key = $cart->addItem(
id: 'products/t-shirt',
quantity: 1,
options: ['Color' => 'Green', 'Size' => 'Medium']
);