primitivesocial/shift4wrapper

Shift4 API 的 Laravel 包装器

1.01 2018-12-27 12:49 UTC

This package is auto-updated.

Last update: 2024-08-28 02:00:44 UTC


README

Shift4 API 的 Laravel 包装器

安装

composer require primitivesocial/shift4wrapper

然后,发布配置文件: php artisan vendor:publish

您需要添加以下 .env 变量。 SHIFT4_API_URL: Shift4 API 的 URL SHIFT4_CLIENT_GUID: Shift4 的 GUID SHIFT4_AUTH_TOKEN: Shift4 的认证令牌 I4GO_API_URL: I4GO 的 API URL SHIFT4_COMPANY_NAME: 在 Shift4 文件夹中的公司名称 SHIFT4_INTERFACE_NAME: 在 Shift4 文件夹中的接口名称

使用方法

获取访问令牌

Shift4 访问令牌是长期有效的,因此您应该存储这些。

$client = new Shift4Wrapper();

$accessToken = $client->accessToken;

创建 I4GO 令牌

$client = new Token($accessToken);

$client->ip('173.49.87.94')
		->expirationMonth(12)
		->expirationYear(30)
		->cardNumber('4321000000001119')
		->cvv('333')
		->cardType('VS')
		->name('John Smith')
		->zip('65000')
		->address('65 Main Street')
		->post();

// Set card value to preserve through tests
$token = $client->getToken();

销售后

$transaction = new Transaction($accessToken);

$transaction->tax(11.14)
		->total(111.45)
		->clerk('1')
		->invoiceNumber('12345')
		->tokenValue($token)
		->purchaseCard(array(
			'customerReference' => 412348,
			'destinationPostalCode' => 19134,
			'productDescriptors' => array('rent')
		))
		->sale();

退款后

$transaction = new Transaction($accessToken);

$transaction->total(200.00)
		->tokenValue($token)
		->invoiceNumber('12345')
		->clerk('5188')
		->refund();

删除发票

因为在这个调用中必须在头部发送发票号码,所以方法结构不同。

$transaction = new Transaction($accessToken);

$transaction->deleteInvoice($randomInvoice);

更多方法可以在测试中查看。

测试

Shift4 要求进行某些测试,以便在生产中使用他们的 API。通过测试可以在 tests 文件夹中找到。测试连接到 Laravel 的 Log 类,这使得将测试结果导出提交给 Shift4变得容易。