hestalabs/payments

此包的最新版本(v1.0.x-dev)没有提供许可证信息。

这是一个简单易用的Laravel和Lumen包,用于在单个位置使用多个支付网关。现在您不需要为多个支付网关安装多个包。这里我们提供了两个最广泛使用的支付网关(PayPal,Stripe),具有易用的方法,例如pay()invoice()refund()等。

v1.0.x-dev 2019-04-20 12:39 UTC

This package is auto-updated.

Last update: 2024-09-21 01:11:53 UTC


README

Latest Stable Version Total Downloads License Monthly Downloads

这是一个简单易用的Laravel和Lumen包,用于在单个位置使用多个支付网关。现在您不需要为多个支付网关安装多个包。这里我们提供了两个最广泛使用的支付网关(PayPal,Stripe),具有易用的方法,例如pay()invoice()refund()等。

安装

通过Composer

适用于LaravelLumen

$ composer require hetsabit/payments ">=1.0"

或者您可以直接在您的composer.json中添加它

"require": {
    "hetsabit/payments": ">=1.0"
}

接下来,运行composer update

Laravel的用法

1). 对于Laravel,将ServiceProvider添加到您的config/app.php

a). 在providers数组中添加

'providers' => array(
    // ...

    Hetsabit\Payments\PaymentsServiceProvider::class,
);

b). 在alias数组中添加别名

'aliases' => array(
    // ...

    'Payment'   => Hetsabit\Payments\Facades\Payment::class,
);

c). 最后通过在Terminal中运行以下命令发布包配置

`php artisan vendor:publish --provider="Hetsabit\Payments\PaymentsServiceProvider"`

Lumen的用法

a). 对于Lumen,创建一个名为config的目录并在其中创建一个名为payments的文件,添加以下代码

<?php

return [
	'payment_type' => env('PAYMENT_TYPE', 'paypal'),
	'stripe' => [
		'key'       => env('STRIPE_KEY'),
		'secret'    => env('STRIPE_SECRET'),
	],
	'paypal_payment' => [
		# Define your application mode here
		'mode' => env('PAYPAL_MODE', 'sandbox'),  //"sanbox" for testing and "live" for production

		# Account credentials from developer portal
		'account' => [
			'client_id'		=> env('PAYPAL_CLIENT_ID', ''),
			'client_secret' => env('PAYPAL_CLIENT_SECRET', ''),
		],

		# Connection Information
			'http' => [
			'connection_time_out' => 30,
			'retry' => 1,
		],

		# Logging Information
		'log' => [
			'log_enabled' => true,

			# When using a relative path, the log file is created
			# relative to the .php file that is the entry point
			# for this request. You can also provide an absolute
			# path here
			'file_name' => '../PayPal.log',

			# Logging level can be one of FINE, INFO, WARN or ERROR
			# Logging is most verbose in the 'FINE' level and
			# decreases as you proceed towards ERROR
			'log_level' => 'FINE',
		],
	],
];

b). 在app目录中创建一个名为Support的目录并在其中创建一个名为helpers.php的文件。现在在您的composer.json中添加以下行。

//在composer.json中

"autoload": {
    "classmap": [
        "database/seeds",
        "database/factories"
    ],
    "psr-4": {
        "App\\": "app/"
    },
    "files": [
        "app/Support/helpers.php"
    ]
},

//在app/Support/helpers.php中

<?php

if ( ! function_exists('config_path')){
    /**
     * Get the configuration path.
     *
     * @param  string $path
     * @return string
     */
    function config_path($path = ''){
        return app()->basePath() . '/config' . ($path ? '/' . $path : $path);
    }
}

c). 前往您的bootstrap/app.php并取消注释那里的withEloquent()并添加以下行

$app->register(Hetsabit\Payments\PaymentsServiceProvider::class);

class_alias('Hetsabit\Payments\Facades\Payment', 'Payment');

$app->configure('payments');

重要说明

a). 在第173行搜索vendor/paypal/rest-api-sdk-php/lib/PayPal/Common/PayPalModel.php

else if(sizeof($v) <= 0 && is_array($v))更改为else if(is_array($v) && sizeof($v) <= 0)

b). 在您的.env中添加凭据

STRIPE_KEY='YOUR_CREDENTIALS'
STRIPE_SECRET='YOUR_CREDENTIALS'

PAYPAL_MODE='YOUR_CREDENTIALS' 			//"sanbox" for testing and "live" for production (default: sandbox)
PAYMENT_TYPE='YOUR_TYPE' 				//paypal, stripe (default: paypal)
PAYPAL_CLIENT_ID='YOUR_CREDENTIALS'
PAYPAL_CLIENT_SECRET='YOUR_CREDENTIALS'

示例

1). 对于PayPal(如果.env中的PAYMENT_TYPE == paypal)

1). 通过PayPal进行支付

//for shipping details 						(Optional)
$shipping = \Payment::shipping();
$shipping->setLine1("3909 Witmer Road")
->setLine2("Niagara Falls")
->setCity("Niagara Falls")
->setState("NY")
->setPostalCode("14305")
->setCountryCode("US")
->setPhone("716-298-1822")
->setRecipientName("Jhone");
	
//if making payment via credit_card (Required if card is set otherwise not required)
$card = \Payment::card();
$card->setType('visa')						
->setNumber(4032038634486363)	//required		
->setExpireMonth(11)	//required	
->setExpireYear(2023)	//required		
->setCvv(123)			//required		
->setFirstName('Abhishek')					
->setLastName('Rana');						
	
//if user wants to add some extra details 	(Optional)
$details = \Payment::details();
$details//>setShippingCharge(1.0)				
->setShippingTax(1.0)	(sub total must be a sumation of all taxes and price)	
->setSubtotal(2.0);

a). 进行支付(PayPal结账)

$pay = \Payment::setTax(0.2)									
->setPrice(1)	//required                          		
->setQuantity(1)	//required							
->setSubTotal(1)															
->setTotal(1.0)	//required                          	
->setCurrency('USD')	(Default USD, otherwise can be provided e.g. USD, AUD etc.)						
->setDescription('New description')			
->setItemName('New Items for shopping')	//required		
->setShippingDetails($shipping)	//required only if shipping details are set as above, otherwise optional		
->setReturnUrl(url('/payment?success=true'))	//required if card is not set (must be a full fletched URl)
->setCancelUrl(url('/payment?success=false'))	//required if card is not set (must be a full fletched URl)
->setExtraParam([		
	'url' => true	//required if you want only redirect URL for PayaPal (useful in cases when you are making API or something). if it is not set then for payment it will redirect to paypal payment screen
])
->setIntent('sale')	(Optional)(Default : sale)(e.g. sale, order, authorize)					
->setDetails($details)						
->pay();	//required
```

b). 通过卡支付,然后设置卡

$pay = \Payment::setTax(0.2)									
->setPrice(1)	//required                          		
->setQuantity(1)	//optional							
->setSubTotal(1)	//optional
->setAmount(1)		//required           	
->setCurrency('USD')	(Default USD, otherwise can be provided e.g. USD, AUD etc.)						
->setDescription('New description')			
->setItemName('New Items for shopping')	//required		
->setShippingDetails($shipping)	//required only if shipping details are set as above, otherwise optional		
->setCard($card)	//required only if payment method is set as `credit_card` otherwise not required
->setIntent('sale')	(Optional)(Default : sale)(e.g. sale, order, authorize)					
->setDetails($details)						
->pay();	//required

b). 对于任何通过PayPal进行的发票或支付详情

$payment_id = 'PAY-1JK339012V705711ALPC3QSI';	: Required(fetch this id, when you are making transaction and store it safe)
$payment_details = \Payment::invoice($payment_id);

c). 对于任何通过PayPal进行的退款

$transaction_id = '3S7574554G079694D'; : Required(fetch this id, when you are making transaction and store)
$refund = \Payment::setAmount(0.11)
->setCurrency('USD')
->setReason('to refund the amount reason')
->refund($transaction_id);  

2). 对于Stripe(如果.env中的PAYMENT_TYPE == stripe)

//initialising the card object
$card = Payment::card();
$card->setNumber(4242424242424242)	: integer (Required)
->setExpireYear(2020)	: integer (Required)
->setExpireMonth(06)	: integer (Required)
->setCvv(314);	: integer (Required)
	
//making payments
$pay = \Payment::setAmount(1)	: integer (Required)
->setDescription('for whatever')	: string  (Optional)
->setCard($card)	: object  (Required)
->pay();	: required

a). 通过Stripe进行支付

$payment_id = 'ch_1DK0jWB108n83JtHxlqSCqrK';	: Required(fetch this id, when you are making transaction and store it safe)

$payment_details = \Payment::invoice($payment_id);

b). 获取发票或支付详情

$transaction_id = 'ch_1DK0j1B108n83JtH236d8aH5'; : Required(fetch this id, when you are making transaction and store)
$refund = \Payment::setAmount(1)
->setReason('duplicate')
->refund($transaction_id); 

c). 获取任何交易的退款

$ vendor Hetsabit/payments

测试

环境

PAYPAL_MODE = sandbox/live

a). 只需将PayPal的.env中的环境从env更改为测试的sandbox和生产的live

安全

b). 对于Stripe,只需更改实时凭据,在激活账户以进行实时支付后,一切都将正常。

如果发现任何与安全相关的问题,请通过电子邮件friends@hestabit.com报告,而不是使用问题跟踪器。

许可证