miguelv/easy-payment-bundle

在Symfony之上实现简单支付

dev-master 2016-12-10 14:18 UTC

This package is not auto-updated.

Last update: 2024-09-18 18:37:06 UTC


README

本包正在积极开发中,目前尚未准备好使用。

本包的目标是在Symfony之上提供可完全自定义和可扩展的支付方式。

安装

步骤 1: 下载包

打开命令行,进入您的项目目录,并执行以下命令以下载此包的最新稳定版本

@todo

$ composer require miguelv/easy-payment-bundle:dev-master

步骤 2: 配置包

然后,通过将其添加到项目中app/AppKernel.php文件中注册的包列表中来启用该包

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Miguelv\EasyPaymentBundle\EasyPaymentBundle(),
        );

        // ...
    }

    // ...
}

添加网关配置,目前只提供Stripe网关。在Stripe网站上获取您的API密钥。

    easy_payment.stripe.api_key: "%easy_payment.stripe.api_key%"
    easy_payment.stripe.publishable_key: "%easy_payment.stripe.publishable_key%"

添加到您的app/config/config.yml的最小配置

easy_payment:
    stripe:
        apiKey: "%easy_payment.stripe.api_key%"
        publishable_key: "%easy_payment.stripe.publishable_key%"

    default:
        success_path: 'home'
        fail_path: 'pricing'

在app/config/routing.yml中添加路由

//...
easy_payment:
    resource: "@EasyPaymentBundle/Resources/config/routing/routing.xml"
//...

使用方法

最简单的方法是在模板中渲染表单。

//...
{% render(controller('easy_payment.gateway.stripe_payment.controller:renderFormAction', {
      description: 'Foo Product (12$)',
      amount: 1200
    }))
%}
//...


You can pass aditional information in the render call:

//...
{% render(controller('easy_payment.gateway.stripe_payment.controller:renderFormAction', {
      description: 'Foo Product (12$)',
      amount: 1200,
      currency: 'usd',
      metadata: {"order_id": "12345"}
    }))
%}
//...

If you want for example private information to be added, better override the service controller. Because in this bundle, the
controllers are declared as services, you can override the controllers, modifiying the class loaded.

```yaml
easy_payment:
    stripe:
        controller: 'MyAppBundle\Controller\StripePaymentController'
//...

然后创建自己的服务,并扩展原始服务,重写paymentAction方法

//...

use Miguelv\EasyPaymentBundle\Controller\StripePaymentController

//...

class MyStripePaymentControllerService extends StripePaymentController
{
    public function paymentAction(Request $request)
    {
        //your code here

    //...
}

完整配置

easy_payment:
    stripe:
        controller: 'Miguelv\EasyPaymentBundle\Controller\StripePaymentController'
        apiKey: '%easy_payment.stripe.api_key%'
        publishable_key: "%easy_payment.stripe.publishable_key%"
        manager: 'Miguelv\EasyPaymentBundle\Gateways\Stripe\StripeManager'
        form:
            type: 'easy_payment_stripe_type'
            validation_groups: ['Default']
        data: # You can put here any default values admited by Stripe: see https://stripe.com/docs/checkout
          image: 'http://www.my-company.com/logo.png'
          name: 'My Company'
          description: 'Foo Product (12$)'
          locale: auto
          zip-code: true
          billing-address: false
          amount: 1000 #Yo can also put a default amount, then you can skip this data when rendering the form

    default:
        success_path: 'easy_payment_home' # The bundle add success message into symfony message flash bag
        fail_path: 'easy_payment_fail' # The bundle add fail message into symfony message flash bag
        currency: 'usd' # three letter defining currency ('eur' for euro).