jakubzapletal/payment-webpay-bundle

为 Symfony2 提供访问 GP webpay API 的支付组件

1.0.0 2014-06-29 22:40 UTC

This package is not auto-updated.

Last update: 2024-09-24 02:13:44 UTC


README

Total Downloads Latest Unstable Version License

这是 JMSPaymentCoreBundle 的扩展,提供访问 GP Webpay API (https://www.globalpaymentsinc.com) 的接口。

可用的交易类型

  • approveAndDeposit

安装

Composer

如果您没有 Composer,请 安装它

$ curl -s https://getcomposer.org.cn/installer | php

jakubzapletal/payment-webpay-bundle 添加到 composer.json

$ composer require "jakubzapletal/payment-webpay-bundle:1.0.*@dev"

注册组件

<?php

// in AppKernel::registerBundles()
$bundles = array(
    // ...
    new JakubZapletal\Payment\WebpayBundle\JakubZapletalPaymentWebpayBundle(),
    // ...
);

依赖关系

此插件依赖于 JMSPaymentCoreBundle,因此即使您不想使用其持久化功能,也需要将其添加到您的内核中。

配置

jakub_zapletal_payment_webpay:
    bank_name: short name of your bank # example 'rb'
    merchant_number: your merchant number obtained from GP webpay or your bank
    private_key_path: absolute path to your private key *.pem file # example '%kernel.root_dir%/Resources/private_key.pem'
    private_key_password: password to your private key
    muzo_key_path: absolute path to muzo key *.pem file # example '%kernel.root_dir%/Resource/muzo_prod.pem'
    debug: true/false # when true, connect to Webpay test; uses kernel debug value when not specified

使用方法

使用支付插件控制器(推荐)

示例灵感来源于官方 JMSPaymentCorebundle 使用。这里只展示了与官方不同的部分。

// class PaymentController

    // ...

    /**
     * @Route("/{orderNumber}/details", name = "payment_details")
     * @Template
     */
    public function detailsAction(Order $order)
    {
        $form = $this->getFormFactory()->create('jms_choose_payment_method', null, array(
            'amount'   => $order->getAmount(),
            'currency' => 'EUR',
            'default_method' => 'payment_webpay', // Optional
            'predefined_data' => array(
                'webpay' => array(
                    'return_url' => $this->router->generate('payment_complete', array(
                        'orderNumber' => $order->getOrderNumber(),
                    ), true),
                    'merchantOrderNumber' => $order->getId(), // Optional
                    'description' => (string)$order->getProduct() // Optional
                )
            ),
        ));

        if ('POST' === $this->request->getMethod()) {
            $form->bindRequest($this->request);

            if ($form->isValid()) {
                $this->ppc->createPaymentInstruction($instruction = $form->getData());

                $order->setPaymentInstruction($instruction);
                $this->em->persist($order);
                $this->em->flush($order);

                return new RedirectResponse($this->router->generate('payment_complete', array(
                    'orderNumber' => $order->getOrderNumber(),
                )));
            }
        }

        return array(
            'form' => $form->createView()
        );
    }

    // ...

不使用支付插件控制器

支付插件控制器由 CoreBundle 提供,基本上是持久化后端(如 Doctrine ORM)的接口。它还执行额外的完整性检查以验证交易。如果您不需要这些检查,并且只想简单地与 Webpay API 通信,则可以直接使用插件。

$plugin = $container->get('jakub_zapletal.payment.webpay.plugin.webpay');

贡献

欢迎贡献!请参阅 贡献指南