grimmlink/alipay-bundle

GrimmlinkAlipayBundle

安装: 132

依赖者: 0

建议者: 0

安全性: 0

星标: 2

关注者: 2

分支: 2

开放问题: 0

类型:symfony-bundle

2.0 2017-04-13 11:23 UTC

This package is auto-updated.

Last update: 2024-09-10 00:48:34 UTC


README

SensioLabsInsight

这是一个用于帮助您使用支付宝跨境网站支付系统(http://global.alipay.com/product/websitepayment.htm)创建和提交支付的Symfony Bundle。

要求

  • cURL
  • openssl

安装

使用composer安装

    ...
    "require": {
        ...
        "grimmlink/alipay-bundle": "dev-master",
        ...
    },
    ...

将此bundle添加到您的app/AppKernel.php文件中

public function registerBundles()
{
    return array(
        // ...
        new Grimmlink\AlipayBundle\GrimmlinkAlipayBundle(),
        // ...
    );
}

配置

您的个人账户信息必须设置在config.yml中

# Grimmlink Alipay Bundle
grimmlink_alipay:
    config:
        https_verify_url:   https://mapi.alipay.net/gateway.do          # The API endpoint
        key:                'abcdefghijklmnopqrstuvwxyz123456'          # Your account key - alipay testing environment: 760bdzec6y9goq7ctyx96ezkz78287de
    parameters:
        partner:            '1234567890123456'                          # Your partner number - alipay testing environment: 2088101122136241
        currency:           EUR                                         # Cannot be CNY / RMB !!
        input_charset:      utf-8                                       # 
        service:            create_forex_trade                          # 

路由

# Grimmlink Alipay Bundle
grimmlink_alipay:
    resource: '@GrimmlinkAlipayBundle/Resources/config/routing.yml'

用法

在您的支付控制器中

...
    $apr = $this->get('grimmlink_alipay.request_handler');
    $apr->setParameters(array(
        'notify_url'        => $this->generateUrl('grimmlink_alipay_notify', array(), true),
        'return_url'        => $this->generateUrl('payment_alipay_return', array(), true), // make it your own
        'out_trade_no'      => $ref,  // make it your own
        'total_fee'         => '0.01', // make it your own
        'subject'           => 'Payment title', // make it your own
        'body'              => 'This is the payment description', // make it your own
    ));
    
    return $this->render('PaymentBundle:Alipay:pay.html.twig', array(
        'url'       => $apr->getUrl(),
        'form'      => $apr->getForm()->createView(),
    ));
...

不要忘记为您的返回URL创建控制器动作,不要在内部包含支付处理,这是在通知事件监听器中完成的。

然后,创建您自己的支付宝通知服务监听器,如下所示

services:
    ...
    alipay.notification:
        class: Grimmlink\PaymentBundle\EventListener\AlipayListener
        tags:
            - { name: kernel.event_listener, event: alipay.notify_response, method: onAlipayNotificationResponse }

创建您的监听器类,并将您的支付逻辑放在AlipayResponseEvent中

  • data : 支付宝发送的查询参数
  • response : 如果通知已验证,则为"true"
  • signed : 布尔值 - 支付宝响应的签名是否有效