承接 mscode-pl/laravel-cashbill 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mscode-pl/laravel-cashbill

最新稳定版本:1.0.0

Composer 安装命令:

composer require mscode-pl/laravel-cashbill

包简介

Package for easily integrating cashbill payments with Laravel.

README 文档

README

Package for easily integrating Cashbill payments with Laravel.

Installation

  1. Install composer package using command:
  composer require mscode-pl/laravel-cashbill
  1. Publish configuration files to your project
  php artisan vendor:publish --provider="MsCode\Cashbill\CashbillServiceProvider"
  1. Run migrations
  php artisan migrate 

Setup

Firstly you need to move environmental variables from .env.example to .env:

CASHBILL_MODE=dev
CASHBILL_SHOP_ID=
CASHBILL_SECRET_KEY=

If you are in testing mode, set CASHBILL_MODE to dev. When in production, switch it to prod. Retrieve the remaining variables from the CashBill shop settings.

In the configuration file, you can define return routes, default values, the database table name, and the columns for collecting personal data. After modifying columns, rerun the migration process.

Ensure that you specify the same notification route as in the CashBill shop settings. This URL is used to verify transactions and is set by default to /api/cashbill/notification

Usage/Examples

To initiate a transaction, create a Payload object in your controller and assign values. Then, create a Payment object, pass the Payload, and call redirect(). This action will start the transaction and redirect the user to the Cashbill payment page. You can also create a PersonalData object. The first name, surname, and email address will be automatically filled on the Cashbill page.

<?php

namespace App\Http\Controllers;

use MsCode\Cashbill\Payload;
use MsCode\Cashbill\Payment;
use MsCode\Cashbill\PersonalData;

class CashbillExample extends Controller
{
    public function handle()
    {
        $payload = new Payload();
        $payload->setTitle("Example title");
        $payload->setAmount(9.5);

        $personalData = new PersonalData();
        $personalData->setEmail("email@example.com");
        $personalData->setFirstName("Name");
        $personalData->setSurname("Surname");
        $payload->setPersonalData($personalData);

        $payment = new Payment($payload);
        return $payment->redirect();
    }
}

Upon transaction creation, the TransactionCreated event is triggered. You can use it to retrieve the payload and order ID to associate the transaction with a specific user. To achieve this, create a listener and register it in your EventServiceProvider.

protected $listen = [
    TransactionCreated::class => [
        ExampleListener::class
    ]
];

By default, all transaction status changes are handled by the package. The TransactionSuccessfullyCompleted event is triggered after receiving a PositiveFinish signal from Cashbill. Otherwise, for status changes, the TransactionStatusChanged event is triggered.

If you prefer to update order data manually, you can create an Order object by passing a specific order ID to the constructor and then calling the update() method, which returns a PaymentDetails object.

$order = new Order($orderId);
$paymentDetails = $order->update();

License

This package is distributed under the MIT license

统计信息

  • 总下载量: 49
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-07-30