mysho/comgate-bundle

安装: 9

依赖者: 0

建议者: 0

安全性: 0

星标: 0

关注者: 0

分支: 4

类型:symfony-bundle

1.0.8 2024-08-27 09:01 UTC

This package is auto-updated.

Last update: 2024-09-27 09:10:15 UTC


README

Comgate支付的symfony包

安装

步骤 1: 使用composer下载MyshoComgateBundle

使用composer Composer 需要 mysho/comgate-bundle

$ composer require mysho/comgate-bundle

步骤 2: 启用包

在kernel中启用该包

<?php

// app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
        new Mysho\ComgateBundle\MyshoComgateBundle(),
        // ...
    );
}

步骤 3: 配置MyshoComgateBundle

以下是使用MyshoComgateBundle在应用程序中进行配置的必要最小示例

# .env

###> mysho/comgate-bundle ###
MERCHANT_ID="your merchant id"
SECRET_KEY="secret key from comgate dashboard"
TEST_MODE=false
###< mysho/comgate-bundle ###

步骤 4: 使用MyshoComgateBundle

# CartController

/**
     * @Route("/cart/payment", name="cart_payment")
     * @param ComgateConnector $comgate
     * @param Request
     * @return Response
     */
    public function payment(ComgateConnector $comgate): Response
    {
        
        $payment = new CreatePayment('PRICE', 'Your order ID', $this->getUser()->getEmail(), 'Some product');
        // to create payment on background according to API requirements
        $payment->setPrepareOnly(true);
        $response = $comgate->send($payment);
        if($response->getMessage()=="OK"){
            // do something with cart
            return $this->redirect($response->getRedirectUrl());
        }

        return $this->render('cart/payment.html.twig', []);
    }