nexteam/trivel

非官方的 Laravel Tripay 包装器

1.1.0 2023-09-01 03:54 UTC

This package is auto-updated.

Last update: 2024-09-30 01:38:14 UTC


README

非官方的 Tripay 包装器,用于 Laravel

CV Nexteam Teknologi Indonesia维护

使用方法

  • 使用命令安装: composer require nexteam/trivel

  • 在您的.env文件中添加配置,如下所示

TRIVEL_BASE_URL="https://tripay.co.id/api-sandbox"
TRIVEL_API_KEY=...
TRIVEL_MERCHANT_CODE=...
TRIVEL_PRIVATE_KEY=...
  • TrivelServiceProvider添加到config/app.php
'providers' => ServiceProvider::defaultProviders()->merge([
        // another service provider
        \Nexteam\Trivel\TrivelServiceProvider::class
    ])->toArray(),
  • 别忘了通过运行命令发布trivel-configphp artisan vendor:publish trivel-config

示例

<?php

use Nexteam\Trivel\Dto\Transaction\ClosedTransactionRequest;
use Nexteam\Trivel\Exception\TrivelException;
use Nexteam\Trivel\Transaction\TrivelClosedTransaction;

// create close (one-time) transaction
// for the detail see official tripay documentation here : https://tripay.co.id/developer?tab=transaction-create

$payload = [
    'method' => 'BRIVA',
    'merchant_ref' => "INV0001",
    'amount' => 500000,
    'customer_name' => 'Nama Pelanggan',
    'customer_email' => 'emailpelanggan@domain.com',
    'customer_phone' => '081234567890',
    'order_items' => [
        [
            'sku' => 'FB-06',
            'name' => 'Nama Produk 1',
            'price' => 500000,
            'quantity' => 1,
            'product_url' => 'https://tokokamu.com/product/nama-produk-1',
            'image_url' => 'https://tokokamu.com/product/nama-produk-1.jpg',
        ],

    ],
    'return_url' => 'https://domainanda.com/redirect',
    'expired_time' => (time() + (24 * 60 * 60)),
];

try {
    $data = TrivelClosedTransaction::make(new ClosedTransactionRequest($payload["merchant_ref"], $payload["amount"], $payload));
    $payCode = $data['pay_code'];
    $checkOutUrl = $data['checkout_url'];
    dd($data);
} catch (TrivelException $e) {
    // handling your exception here
}