Skip to content

Commit

Permalink
Improve PHP types
Browse files Browse the repository at this point in the history
  • Loading branch information
alecritson committed May 23, 2024
1 parent f72a310 commit d29998a
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions packages/stripe/src/Managers/StripeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Illuminate\Support\Collection;
use Lunar\Models\Cart;
use Lunar\Models\CartAddress;
use Stripe\Charge;
use Stripe\Exception\ApiErrorException;
use Stripe\Exception\InvalidRequestException;
use Stripe\PaymentIntent;
use Stripe\Stripe;
Expand All @@ -28,10 +31,8 @@ public function getClient(): StripeClient

/**
* Create a payment intent from a Cart
*
* @return \Stripe\PaymentIntent
*/
public function createIntent(Cart $cart)
public function createIntent(Cart $cart): PaymentIntent
{
$shipping = $cart->shippingAddress;

Expand Down Expand Up @@ -68,7 +69,7 @@ public function createIntent(Cart $cart)
return $paymentIntent;
}

public function syncIntent(Cart $cart)
public function syncIntent(Cart $cart): void
{
$meta = (array) $cart->meta;

Expand All @@ -86,11 +87,8 @@ public function syncIntent(Cart $cart)

/**
* Fetch an intent from the Stripe API.
*
* @param string $intentId
* @return null|\Stripe\PaymentIntent
*/
public function fetchIntent($intentId)
public function fetchIntent(string $intentId): ?PaymentIntent
{
try {
$intent = PaymentIntent::retrieve($intentId);
Expand All @@ -116,20 +114,21 @@ public function getCharges(string $paymentIntentId): Collection
return collect();
}

public function getCharge($chargeId)
public function getCharge(string $chargeId): ?Charge
{
return $this->getClient()->charges->retrieve($chargeId);
try {
return $this->getClient()->charges->retrieve($chargeId);
} catch (ApiErrorException $e) {

}

return null;
}

/**
* Build the intent
*
* @param int $value
* @param string $currencyCode
* @param \Lunar\Models\CartAddress $shipping
* @return \Stripe\PaymentIntent
*/
protected function buildIntent($value, $currencyCode, $shipping)
protected function buildIntent(int $value, string $currencyCode, CartAddress $shipping): PaymentIntent
{
return PaymentIntent::create([
'amount' => $value,
Expand Down

0 comments on commit d29998a

Please sign in to comment.