alaa-elsaid/laravel-tap-payments

Laravel >= 5 的 Tap Payment REST API 包

v1.0.1 2024-06-16 08:38 UTC

This package is auto-updated.

Last update: 2024-09-16 09:05:14 UTC


README

Laravel 包,用于 https://www.tap.company 支持 Laravel 5.5 及以上版本

安装

只需运行

composer require "alaa-elsaid/laravel-tap-payments"

对于 Laravel >= 5.5,这就是全部。此包支持 Laravel 新的包发现功能。

否则,您需要打开 /config/app.php 并将服务提供者添加到您的 providers 数组中。

'providers' => [
	\Alaa\TapPayment\TapPaymentServiceProvider::class
]

现在添加别名。

'aliases' => [
	'TapPayment' => \Alaa\TapPayment\Facade\TapPayment::class
]

配置

要发布配置,运行

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

并使用您自己的信息修改配置文件。文件位于 /config/tap-payment.php

您可以在您的 .env 文件中使用这些环境变量

TAP_PAYMENT_API_KEY=your_api_key

当前版本功能

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

使用示例

创建费用(进行支付)

use Alaa\TapPayment\Facade\TapPayment;

public function pay()
{
	try{

		$payment = TapPayment::createCharge();

		$payment->setCustomerName( "John Doe" );
		
		$payment->setCustomerPhone( "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();
		$invoice->getPaymentUrl(); // get the payment url to redirect the user to it.

		
	} catch( \Exception $exception ){
		// your handling of request failure
	}
    
    $payment->isSuccess() // check if TapPayment has successfully handled request.
}

查找 ApiInvoice

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
}