ahmedfox / tap_payments

Laravel 的 Tap 支付 REST API 包

dev-master 2023-03-04 20:35 UTC

This package is auto-updated.

Last update: 2024-09-05 00:08:48 UTC


README

此包在平台要求方面有一个更新,以便与 Laravel 9 一起运行

https://github.com/spacemudd/laravel-tap-payments

运行 Laravel 9

https://www.tap.company 集成的库

安装

composer require ahmedfox/tap_payments

对于 Laravel 的旧版本(<5.5)

使用以下内容更新您的 /config/app.php

'providers' => [
    ...
	\Tap\TapPayment\TapPaymentServiceProvider::class
]
'aliases' => [
    ...
	'TapPayment' => \Tap\TapPayment\Facade\TapPayment::class
]

发布

php artisan vendor:publish --provider="Tap\TapPayment\TapPaymentServiceProvider"

配置

使用您的信息更新 /config/tap-payment.php

将以下内容添加到您的 .env 文件中

TAP_PAYMENT_API_KEY=your_api_key

当前版本功能

  • TapPayment::createCharge() - 创建 ApiInvoice
  • TapPayment::findCharge($id) - 通过 ID 查找 ApiInvoice

使用示例

创建费用

use Tap\TapPayment\Facade\TapPayment;

public function pay()
{
	try {
		$payment = TapPayment::createCharge();
		$payment->setCustomerName("John Doe");
		$payment->setCustomerPhone("965", "123456789");
		$payment->setDescription("Some description");
		$payment->setAmount(123);
		$payment->setCurrency("KWD");
		$payment->setSource("src_kw.knet");
		$payment->setRedirectUrl("https://example.com");
		$payment->setPostUrl("https://example.com"); // if you are using post request to handle payment updates
		$payment->setMetaData(['package' => json_encode($package)]); // if you want to send metadata
		$invoice = $payment->pay();
	} catch( \Exception $exception ) {
		// your handling of request failure
	}
    
    $payment->isSuccess(); // check if TapPayment has successfully handled request.
}

获取发票

public function check($id)
{
	try {
		 $invoice = TapPayment::findCharge($id);
	 } catch(\Exception $exception) {
		// your handling of request failure
	}

	$invoice->checkHash($request->header('Hashstring')); // check hashstring to make sure that request comes from Tap
	$invoice->isSuccess(); // check if invoice is paid
	$invoice->isInitiated(); // check if invoice is unpaid yet
}