PHP code example of ruskid / yii2-stripe
1. Go to this page and download the library: Download ruskid/yii2-stripe 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/ */
ruskid / yii2-stripe example snippets
'components' => [
...
'stripe' => [
'class' => 'ruskid\stripe\Stripe',
'publicKey' => "pk_test_xxxxxxxxxxxxxxxxxxx",
'privateKey' => "sk_test_xxxxxxxxxxxxxxxxxx",
],
...
use ruskid\stripe\StripeCheckout;
<?=
StripeCheckout::widget([
'action' => '/',
'name' => 'Demo test',
'description' => '2 widgets ($20.00)',
'amount' => 2000,
'image' => '/128x128.png',
]);
use ruskid\stripe\StripeCheckoutCustom;
<?=
StripeCheckoutCustom::widget([
'action' => '/',
'name' => 'Demo test',
'description' => '2 widgets ($20.00)',
'amount' => 2000,
'image' => '/128x128.png',
'buttonOptions' => [
'class' => 'btn btn-lg btn-success',
],
'tokenFunction' => new JsExpression('function(token) {
alert("Here you should control your token.");
}'),
'openedFunction' => new JsExpression('function() {
alert("Model opened");
}'),
'closedFunction' => new JsExpression('function() {
alert("Model closed");
}'),
]);
use ruskid\stripe\StripeForm;
$form = StripeForm::begin([
'action' => Url::toRoute('payment/create'),
'options' => [
'autocomplete' => 'on',
'data-secret' => 'payment intent client secret',
],
'elementsOptions' => [
'locale' => 'es' // stripe elements language
],
'formEvents' => [
'beforeSubmit' => 'what ever form events',
'submit' => new JsExpression('function(event) {
// you can define as you want
// stripe.handleCardPayment()
// stripe.createToken()
}'),
]
]);
echo $form->cardInput([
'hidePostalCode' => true,
'style' => [
'base' => [
'color' => 'blue',
],
'invalid' => [
'color' => 'red',
'iconColor' => 'red'
]
],
], [
'change' => new JsExpression('function(event) {
if (event.error) {
alert(event.error.message);
} else {
// input is good
}
}')
]);
echo $form->cardNumber();
echo $form->cardExpiry();
echo $form->cardCvc();
echo Html::submitButton('Submit');
StripeForm::end();
sh
php composer.phar