¨4.0.1¨

This commit is contained in:
¨NW¨
2023-12-03 14:07:47 +00:00
parent c08b36d1b6
commit f35052522d
1112 changed files with 43019 additions and 24987 deletions

View File

@@ -3,7 +3,9 @@
namespace Modules\Payment\Gateways;
use Exception;
use PayPalHttp\IOException;
use Illuminate\Http\Request;
use PayPalHttp\HttpException;
use Modules\Order\Entities\Order;
use Modules\Payment\GatewayInterface;
use PayPalCheckoutSdk\Core\PayPalHttpClient;
@@ -18,27 +20,19 @@ class PayPal implements GatewayInterface
public $label;
public $description;
public function __construct()
{
$this->label = setting('paypal_label');
$this->description = setting('paypal_description');
}
public function client()
{
return new PayPalHttpClient($this->environment());
}
private function environment()
{
if (setting('paypal_test_mode')) {
return new SandboxEnvironment(setting('paypal_client_id'), setting('paypal_secret'));
}
return new ProductionEnvironment(setting('paypal_client_id'), setting('paypal_secret'));
}
public function purchase(Order $order, Request $r)
/**
* @throws HttpException
* @throws IOException
*/
public function purchase(Order $order, Request $req)
{
try {
$request = new OrdersCreateRequest;
@@ -51,6 +45,18 @@ class PayPal implements GatewayInterface
return new PayPalResponse($order, $this->client()->execute($request));
}
public function client()
{
return new PayPalHttpClient($this->environment());
}
/**
* @throws HttpException
* @throws IOException
* @throws Exception
*/
public function complete(Order $order)
{
try {
@@ -62,6 +68,7 @@ class PayPal implements GatewayInterface
return new PayPalResponse($order, $this->client()->execute($request));
}
private function buildRequestBody($order)
{
return [
@@ -86,7 +93,7 @@ class PayPal implements GatewayInterface
'reference_id' => $order->id,
'amount' => [
'currency_code' => setting('default_currency'),
'value' => (string) $order->total->round()->amount(),
'value' => (string)$order->total->round()->amount(),
],
'shipping' => [
'name' => [
@@ -110,4 +117,14 @@ class PayPal implements GatewayInterface
],
];
}
private function environment()
{
if (setting('paypal_test_mode')) {
return new SandboxEnvironment(setting('paypal_client_id'), setting('paypal_secret'));
}
return new ProductionEnvironment(setting('paypal_client_id'), setting('paypal_secret'));
}
}