立方蘑菇 / 条纹捆绑
Symfony捆绑包,用于处理Stripe支付
v2.7.3
2017-11-28 10:58 UTC
Requires
- cubicmushroom/payments-stripe: ^1.1.1
- cubicmushroom/value-objects-bundle: ~2.7.1
- doctrine/orm: ~2.4,>=2.4.5
- league/tactician-bundle: ^1.0@dev
- symfony/framework-bundle: ^2.7
Requires (Dev)
- phpspec/phpspec: ^2.3
This package is not auto-updated.
Last update: 2024-09-14 18:18:07 UTC
README
Symfony捆绑包,用于添加Stripe支付支持
安装
使用composer...
$ composer require "cubicmushroom/stripe-bundle" "dev-master"
Symfony设置
通过向您的AppKernel文件中添加以下行来注册捆绑...
// app/AppKernel.php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
//...
new CubicMushroom\Symfony\StripeBundle\CMStripeBundle(),
//...
);
// ...
}
// ...
}
将以下内容添加到您的app/config.yml文件...
cm_stripe:
api_publishable_key: %cm_stripe.api_publishable_key%
api_secret_key: %cm_stripe.api_secret_key%
... 以及以下内容到您的parameters.yml.dist/parameters.yml文件,用parameters.yml文件中的API详情替换~...
parameters:
...
# Stripe Bundle
cm_stripe.api_publishable_key: ~
cm_stripe.api_secret_key: ~
加载JavaScript库
Stripe JS文件及API密钥
将以下twig函数调用添加到包含Stripe支付表单的页面模板中...
{{ cm_stripe_api_script() }}
这会在页面上注入Stripe API JavaScript文件和您的公钥。
捆绑JS文件
首先确保使用app/console assets:install命令安装了捆绑资源。
将以下脚本标签添加到页面的JavaScript文件中...
如果使用assetic...
{% javascripts
{#...#}
'@CMStripeBundle/Resources/public/js/stripe-bundle.js'
{#...#}
output='compiled/js/app.js' %}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
... 或者如果不使用assetic...
<script type="text/javascript" src="/bundles/cmstripe/js/stripe-bundle.js"></script>
自定义错误消息
插件显示的错误消息附加到<.stripe-errors>表单元素(必须在相关表单内),如果不存在,则添加到表单顶部。
您可以使用StripeBundle.EVENTS.FORMAT_ERROR_MSG事件来自定义这些错误消息的格式,该事件在Stripe表单的表标签上触发,使用类似以下的方式...
(function ($) {
'use strict';
//noinspection JSLint,JSUnusedLocalSymbols
/**
*
* @param {Event} event
* @param {{errorMessage: string}} errorDetails
*/
function addStripeErrorFormatting(event, errorDetails) {
errorDetails.errorMessage = '<div class="alert alert-danger fade in">' + errorDetails.errorMessage + '</div>';
}
$(function () {
$('form.stripe-form').on(StripeBundle.EVENTS.FORMAT_ERROR_MSG, addStripeErrorFormatting);
});
}(jQuery));
TakePaymentCommand表单
捆绑包提供了一个名为cm_stripe_take_payment的表单类型。这可以用来显示Stripe支付表单,以及其他TakePaymentCommand字段。