php – 如何在使用Sylius 0.16和Payum实现非现场支付网关时完成订单

前端之家收集整理的这篇文章主要介绍了php – 如何在使用Sylius 0.16和Payum实现非现场支付网关时完成订单前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直在努力探讨如何使用Sylius(sylius / sylius-standard,v0.16)实现经典的离线支付网关.

到目前为止,我在bundle的build()方法中得到了这个:

public function build(ContainerBuilder $container)
{
    /** @var PayumExtension $payum */
    $payum = $container->getExtension('payum');
    $payum->addGatewayFactory(new PayWayOffsiteGatewayFactory());
}

这是我的config.yml:

sylius_payment:
    gateways:
        payway_offsite: PayWay

payum:
    gateways:
        payway_offsite:
            payway_offsite:
                secret_key: %tcompayway.secret_key%
                shop_id:    %tcompayway.shop_id%
                username:   %tcompayway.username%
                password:   %tcompayway.password%
                sandBox:    %tcompayway.sandBox%

%compayway.*%字段配置正常,跳过此部分.
然后我在PayWayOffsiteGatewayFactory类中得到了这个:

class PayWayOffsiteGatewayFactory extends AbstractGatewayFactory
{
    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'payway_offsite';
    }

    /**
     * {@inheritdoc}
     */
    public function addConfiguration(ArrayNodeDefinition $builder)
    {
        parent::addConfiguration($builder);

        $builder->children()
            ->scalarNode('secret_key')->isrequired()->cannotBeEmpty()->end()
            ->scalarNode('shop_id')->isrequired()->cannotBeEmpty()->end()
            ->scalarNode('username')->isrequired()->cannotBeEmpty()->end()
            ->scalarNode('password')->isrequired()->cannotBeEmpty()->end()
            ->booleanNode('sandBox')->defaultTrue()->end()
            ->end();
    }

    /**
     * {@inheritDoc}
     */
    protected function getPayumGatewayFactoryClass()
    {
        return 'WebBurza\PaymentBundle\Payum\PayWay\PayWayGatewayFactory';
    }

    /**
     * {@inheritDoc}
     */
    protected function getComposerPackage()
    {
        return 'webburza/tcompayway';
    }
}

和PayWayGatewayFactory类:

class PayWayGatewayFactory extends GatewayFactory
{
    /**
     * {@inheritDoc}
     * @throws \Payum\Core\Exception\InvalidArgumentException
     */
    protected function populateConfig(ArrayObject $config)
    {
        $config->defaults(array(
            'payum.factory_name'            => 'payway_offsite','payum.factory_title'           => 'PayWay Offsite','payum.action.capture'          => new CaptureOffsiteAction(),'payum.action.capture_null'     => new CaptureOffsiteNullAction(),'payum.action.status'           => new StatusAction(),'payum.action.convert_payment'  => new ConvertPaymentAction(),));

        if (false == $config['payum.api']) {
            $config['payum.default_options'] = array(
                'secret_key'    => '','shop_id'       => '','username'      => '','password'      => '','sandBox'       => true
            );
            $config->defaults($config['payum.default_options']);
            $config['payum.required_options'] = [
                'secret_key','shop_id','username','password','sandBox'
            ];

            $config['payum.api'] = function (ArrayObject $config) {

                $config->validateNotEmpty($config['payum.required_options']);

                $api = new Api([
                    'secret_key'=> $config['secret_key'],'shop_id'   => $config['shop_id'],'username'  => $config['username'],'password'  => $config['password'],'sandBox'   => $config['sandBox'],],$config['payum.http_client']);

                return $api;

            };
        }
    }
}

到目前为止,我的印象是所有这些都更不行(如果我错了,请纠正我).我设法进入了CaptureOffsiteAction的execute方法

public function execute($captureRequest)
    {
        RequestNotSupportedException::assertSupports($this,$captureRequest);
        $model = ArrayObject::ensureArrayObject($captureRequest->getModel());

        $httpRequest = new GetHttpRequest();
        $this->gateway->execute($httpRequest);

        if ($httpRequest->method === 'POST') {
            $status = new GetHumanStatus($model);

            if (isset($httpRequest->request['pgw_transaction_id']) && $httpRequest->request['pgw_transaction_id'] > 0) {
                // mark this order id as paid,convert cart to order,etc.

            } else {
                // mark as Failed/cancelled,redirect back to cart
            }
            return;

        }

        $model['successUrl'] = $captureRequest->getToken()->getTargetUrl();
        $model['failureUrl'] = $captureRequest->getToken()->getTargetUrl();
        $offsiteUrl = $this->api->getOffsiteUrl();

        $data    = $this->api->prepareOffsitePayment($model->toUnsafeArray());
        $headers = ['application/x-www-form-urlencoded'];

        throw new HttpPostRedirect(
            $offsiteUrl,$data,200,$headers
        );

    }

首先,让我们看看,如果我得到这个权利 – 一旦我开始拍摄流程(执行方法) – 事情是否按预期工作,我结束了该方法底部,创造成功与失败的URL,准备异地支付,哈希和所有并最终通过HttpPostRedirect以正确的订单ID,价格等结束在支付网关上.这部分没关系.

支付,在返回到成功的网址后,我又在CaptureOffsiteAction最终::执行和检查pgw_transaction_id – 如果设置,这意味着我从支付回来,我应该发现无论是支付成功订单或取消/失败付款.

问题是:

>如果付款成功 – 如何“关闭”订单(将购物车转换为订单,将付款标记为已捕获等?)
>我在其他支付网关中看到还有很多其他方法 – 让我说我只对通过重定向后的非现场支付感兴趣 – StatusAction做了什么?什么时候打电话?

到目前为止,我发现Payum(和PayumBundle)非常混乱,我已经成功地实现使用OmniPay下一天2个异地网关(在其他非Sylius相关的项目),但似乎无法来解决这个Payum事情. 原文链接:https://www.f2er.com/php/134224.html

猜你在找的PHP相关文章