iget-master/cielo-checkout

此包的最新版本(v8.0.1)没有提供许可证信息。

提供Laravel 5上的简单Cielo Checkout集成

v8.0.1 2022-01-21 01:05 UTC

This package is auto-updated.

Last update: 2024-09-21 06:51:24 UTC


README

此包提供Laravel 5.x上的Cielo Checkout简单集成。

要使用它,您必须有一个Cielo商户ID。如果没有,请参阅Cielo Checkout文档。Cielo可能需要在启用生产账户之前进行同构。

安装

要开始使用,请通过Composer包管理器安装Cielo Checkout

composer require iget-master/cielo-checkout

如果您使用的是Laravel版本低于5.5,您必须在config/app.php文件下的providers部分包含我们的服务提供者

Iget\CieloCheckout\ServiceProvider::class,

Cielo Checkout服务提供者将框架的数据库迁移目录注册为其自己的,因此您应该在注册提供者后迁移数据库。Cielo Checkout迁移将创建存储Cielo订单所需的表。

php artisan migrate

接下来,您应该在RouteServiceProvidermap方法结束后调用Cielo::routes()方法。此方法将注册必要的路由,以便从Cielo接收交易和状态变更通知。

此方法接受一个可选的$options参数来设置您想要的路线。如果需要,您也可以在Route::group()回调中调用它。

<?php
/** ... */
use Cielo;
class RouteServiceProvider extends ServiceProvider
{
    /** ... */
    public function map()
    {
        $this->mapApiRoutes();
        $this->mapWebRoutes();
        Cielo::routes();
    }
    /** ... */
}

在Cielo Checkout控制面板(Vendas Online -> Cielo Checkout -> Configurações -> Pagamentos)中,您应该将通知类型Tipo de Notificação)配置为POST,将通知URLURL de Notificação)和状态变更URLURL de Mudança de Status)分别设置为

https://yourdomain.com/cielo/notify
https://yourdomain.com/cielo/status

这允许Cielo在CieloOrder付款或状态更改时通知您的应用程序。

用法

第一步是创建一个CieloOrder

use Iget\CieloCheckout\Order\Cart;
use Iget\CieloCheckout\Order\Customer;
use Iget\CieloCheckout\Order\Item;
use Iget\CieloCheckout\Order\Shipping;

public function someControllerMethod()
{
    $order = Cielo::make()
        ->setSoftDescriptor('Descriptor') // Max 13 alphanumeric characters without whitespaces. Underline is allowed.
        ->setCart(function(Cart $cart) {
            $cart->add(new Item('My item label', 345.00, 1, Item::TYPE_ASSET);
        })
        ->setShipping(function(Shipping $shipping) {
            $shipping->setType(Shipping::TYPE_WITHOUT);
        })
        ->setCustomer(function(Customer $customer) { // Optional
            $customer->setIdentity('12345678900') // CPF or CNPJ
                ->setFullname('Fulano de tal')
                ->setEmail('fulano@tal.com')
                ->setPhone('123456789');
        });

    $payableModel = YourOrderModel::find(3232);

    // This will create a new CieloOrder model, and associate it to your $payableModel.
    // If successful, this will generate an URL to where you should redirect your user.
    $redirectUrl = $order->request($payableModel);

    return response()->redirectTo($redirectUrl);
}

当您的客户付款时,您的应用程序将会收到通知。您可以通过观察Iget\CieloCheckout\Events\PaymentStatusHasChanged事件来在收到付款后执行您的逻辑。

此事件将提供对公共属性的访问:$cieloOrder$oldStatus$newStatus

免责声明

此包是免费和开源的。包作者与Cielo(商标)无关,并且不对使用它引起的任何后果负责。