Update HasBitinflowPaymentsWallet.php

This commit is contained in:
2022-09-28 21:15:09 +02:00
committed by GitHub
parent f929f32887
commit 4fdbe165bc

View File

@@ -60,11 +60,7 @@ trait HasBitinflowPaymentsWallet
*/ */
public function getBalance(): ?float public function getBalance(): ?float
{ {
try { return $this->getPaymentsUser()->data->balance;
return $this->getPaymentsUser()->data->balance;
} catch (GuzzleException $e) {
return null;
}
} }
/** /**
@@ -76,14 +72,10 @@ trait HasBitinflowPaymentsWallet
*/ */
public function depositBalance(float $amount, string $decription): bool public function depositBalance(float $amount, string $decription): bool
{ {
try { $this->asPaymentsUser('PUT', sprintf('wallet/deposit', [
$this->asPaymentsUser('PUT', sprintf('wallet/deposit', [ 'amount' => $amount,
'amount' => $amount, 'decription' => $decription,
'decription' => $decription, ]));
]));
} catch (GuzzleException $e) {
return false;
}
} }
/** /**
@@ -95,18 +87,14 @@ trait HasBitinflowPaymentsWallet
*/ */
public function chargeBalance(float $amount, string $decription): bool public function chargeBalance(float $amount, string $decription): bool
{ {
try { $order = $this->createOrder([
$order = $this->createOrder([ 'name' => $decription,
'name' => $decription, 'description' => 'one-time payment',
'description' => 'one-time payment', 'amount' => 1,
'amount' => 1, 'price' => $amount,
'price' => $amount, ]);
]);
return $this->checkoutOrder($order->id); return $this->checkoutOrder($order->id);
} catch (GuzzleException $e) {
return false;
}
} }
/** /**
@@ -116,11 +104,7 @@ trait HasBitinflowPaymentsWallet
*/ */
public function getVat(): ?int public function getVat(): ?int
{ {
try { return $this->getPaymentsUser()->data->taxation->vat;
return $this->getPaymentsUser()->data->taxation->vat;
} catch (GuzzleException $e) {
return null;
}
} }
/** /**
@@ -130,11 +114,7 @@ trait HasBitinflowPaymentsWallet
*/ */
public function getWallets(): ?array public function getWallets(): ?array
{ {
try { return $this->getPaymentsUser()->data->wallets;
return $this->getPaymentsUser()->data->wallets;
} catch (GuzzleException $e) {
return null;
}
} }
/** /**
@@ -145,11 +125,7 @@ trait HasBitinflowPaymentsWallet
*/ */
public function hasWallet(): ?bool public function hasWallet(): ?bool
{ {
try { return $this->getPaymentsUser()->data->has_wallet;
return $this->getPaymentsUser()->data->has_wallet;
} catch (GuzzleException $e) {
return null;
}
} }
/** /**
@@ -160,44 +136,30 @@ trait HasBitinflowPaymentsWallet
*/ */
public function setDefaultWallet(string $token): bool public function setDefaultWallet(string $token): bool
{ {
try { $this->asPaymentsUser('PUT', sprintf('wallets/default', [
$this->asPaymentsUser('PUT', sprintf('wallets/default', [ 'token' => $token
'token' => $token ]));
]));
} catch (GuzzleException $e) {
return false;
}
return true; return true;
} }
/** /**
* Get subscriptions from user. * Get subscriptions from user.
* *
* @return array|null * @return object|null
*/ */
public function getSubscriptions(): ?array public function getSubscriptions(): ?object
{ {
try { return $this->asPaymentsUser('GET', 'subscriptions');
return $this->getPaymentsUser()->data->subscriptions;
} catch (GuzzleException $e) {
return null;
}
} }
/** /**
* @param string $name * @param string $id
* @return object|null * @return object|null
*/ */
public function getSubscription(string $name = 'default'): ?object public function getSubscription(string $id): ?object
{ {
foreach ($this->getSubscriptions() as $subscription) { return $this->asPaymentsUser('GET', sprintf('subscriptions/%s', $id));
if (isset($subscription->payload->name) && $subscription->payload->name === $name) {
return $subscription;
}
}
return null;
} }
/** /**
@@ -222,11 +184,12 @@ trait HasBitinflowPaymentsWallet
'checkout' => $checkout 'checkout' => $checkout
]); ]);
try { return $this->asPaymentsUser('POST', 'subscriptions', $attributes)->data;
return $this->asPaymentsUser('POST', 'subscriptions', $attributes)->data; }
} catch (GuzzleException $e) {
return false; public function createSubscriptionCheckoutIntent($subscription, $success_path = null)
} {
return sprintf('%ssubscriptions/%s/?continue_url=%s', config('bitinflow-accounts.payments.dashboard_url'), $subscription, urlencode(url()->to($success_path)));
} }
/** /**
@@ -248,11 +211,7 @@ trait HasBitinflowPaymentsWallet
*/ */
public function checkoutSubscription(string $id): bool public function checkoutSubscription(string $id): bool
{ {
try { $this->asPaymentsUser('PUT', sprintf('subscriptions/%s/checkout', $id));
$this->asPaymentsUser('PUT', sprintf('subscriptions/%s/checkout', $id));
} catch (GuzzleException $e) {
return false;
}
return true; return true;
} }
@@ -265,11 +224,7 @@ trait HasBitinflowPaymentsWallet
*/ */
public function revokeSubscription(string $id): bool public function revokeSubscription(string $id): bool
{ {
try { $this->asPaymentsUser('PUT', sprintf('subscriptions/%s/revoke', $id));
$this->asPaymentsUser('PUT', sprintf('subscriptions/%s/revoke', $id));
} catch (GuzzleException $e) {
return false;
}
return true; return true;
} }
@@ -282,11 +237,7 @@ trait HasBitinflowPaymentsWallet
*/ */
public function resumeSubscription(string $id): bool public function resumeSubscription(string $id): bool
{ {
try { $this->asPaymentsUser('PUT', sprintf('subscriptions/%s/resume', $id));
$this->asPaymentsUser('PUT', sprintf('subscriptions/%s/resume', $id));
} catch (GuzzleException $e) {
return false;
}
return true; return true;
} }
@@ -294,15 +245,11 @@ trait HasBitinflowPaymentsWallet
/** /**
* Get orders from user. * Get orders from user.
* *
* @return array|null * @return object|null
*/ */
public function getOrders(): ?array public function getOrders(): ?object
{ {
try { return $this->asPaymentsUser('GET', 'orders');
return $this->getPaymentsUser()->data->orders;
} catch (GuzzleException $e) {
return null;
}
} }
/** /**
@@ -311,11 +258,7 @@ trait HasBitinflowPaymentsWallet
*/ */
public function getOrder(string $id): ?object public function getOrder(string $id): ?object
{ {
try { return $this->asPaymentsUser('GET', sprintf('orders/%s', $id));
return $this->asPaymentsUser('GET', sprintf('orders/%s', $id));
} catch (GuzzleException $e) {
return null;
}
} }
/** /**
@@ -333,11 +276,7 @@ trait HasBitinflowPaymentsWallet
'checkout' => $checkout 'checkout' => $checkout
]); ]);
try { return $this->asPaymentsUser('POST', 'orders', $attributes)->data;
return $this->asPaymentsUser('POST', 'orders', $attributes)->data;
} catch (GuzzleException $e) {
return false;
}
} }
/** /**
@@ -348,11 +287,7 @@ trait HasBitinflowPaymentsWallet
*/ */
public function checkoutOrder(string $id): bool public function checkoutOrder(string $id): bool
{ {
try { $this->asPaymentsUser('PUT', sprintf('orders/%s/checkout', $id));
$this->asPaymentsUser('PUT', sprintf('orders/%s/checkout', $id));
} catch (GuzzleException $e) {
return false;
}
return true; return true;
} }
@@ -365,15 +300,31 @@ trait HasBitinflowPaymentsWallet
*/ */
public function revokeOrder(string $id): bool public function revokeOrder(string $id): bool
{ {
try { $this->asPaymentsUser('PUT', sprintf('orders/%s/revoke', $id));
$this->asPaymentsUser('PUT', sprintf('orders/%s/revoke', $id));
} catch (GuzzleException $e) {
return false;
}
return true; return true;
} }
public function createCheckoutSession(array $payload)
{
return $this->asPaymentsUser('POST', 'checkout-sessions', $payload);
}
public function getCheckoutSession(string $id)
{
return $this->asPaymentsUser('GET', sprintf('checkout-sessions/%s', $id));
}
public function checkoutCheckoutSession(string $id)
{
return $this->asPaymentsUser('PUT', sprintf('checkout-sessions/%s/checkout', $id));
}
public function revokeCheckoutSession(string $id)
{
return $this->asPaymentsUser('PUT', sprintf('checkout-sessions/%s/revoke', $id));
}
/** /**
* A setup intent guides you through the process of setting up and saving * A setup intent guides you through the process of setting up and saving
* a customer's payment credentials for future payments. * a customer's payment credentials for future payments.