From daf9972a1b5c682ebed2fea5e153c4c9ee7386a7 Mon Sep 17 00:00:00 2001 From: hutao Date: Wed, 8 Jan 2025 11:42:16 +0800 Subject: [PATCH 1/6] feat(Checkout): Add request option parameters -Add $opts parameter to Checkout and CheckoutBuilder classes -Allow custom request options to be passed when creating Checkouts -Add type import comments for PHPStan and Psalm --- src/Checkout.php | 9 +++++++-- src/CheckoutBuilder.php | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Checkout.php b/src/Checkout.php index 99a7ea5c..234b99a2 100644 --- a/src/Checkout.php +++ b/src/Checkout.php @@ -9,6 +9,10 @@ use JsonSerializable; use Stripe\Checkout\Session; +/** + * @phpstan-import-type RequestOptionsArray from \Stripe\Util\RequestOptions + * @psalm-import-type RequestOptionsArray from \Stripe\Util\RequestOptions + */ class Checkout implements Arrayable, Jsonable, JsonSerializable, Responsable { /** @@ -66,9 +70,10 @@ public static function customer($owner, $parentInstance = null) * @param \Illuminate\Database\Eloquent\Model|null $owner * @param array $sessionOptions * @param array $customerOptions + * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts * @return \Laravel\Cashier\Checkout */ - public static function create($owner, array $sessionOptions = [], array $customerOptions = []) + public static function create($owner, array $sessionOptions = [], array $customerOptions = [], $opts = null) { $data = array_merge([ 'mode' => Session::MODE_PAYMENT, @@ -107,7 +112,7 @@ public static function create($owner, array $sessionOptions = [], array $custome $data['cancel_url'] = $sessionOptions['cancel_url'] ?? route('home').'?checkout=cancelled'; } - $session = $stripe->checkout->sessions->create($data); + $session = $stripe->checkout->sessions->create($data, $opts); return new static($owner, $session); } diff --git a/src/CheckoutBuilder.php b/src/CheckoutBuilder.php index 40d94600..29d91a02 100644 --- a/src/CheckoutBuilder.php +++ b/src/CheckoutBuilder.php @@ -6,6 +6,10 @@ use Laravel\Cashier\Concerns\AllowsCoupons; use Laravel\Cashier\Concerns\HandlesTaxes; +/** + * @phpstan-import-type RequestOptionsArray from \Stripe\Util\RequestOptions + * @psalm-import-type RequestOptionsArray from \Stripe\Util\RequestOptions + */ class CheckoutBuilder { use AllowsCoupons; @@ -60,9 +64,10 @@ public static function make($owner = null, $instance = null) * @param array|string $items * @param array $sessionOptions * @param array $customerOptions + * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts * @return \Laravel\Cashier\Checkout */ - public function create($items, array $sessionOptions = [], array $customerOptions = []) + public function create($items, array $sessionOptions = [], array $customerOptions = [], $opts = null) { $payload = array_filter([ 'allow_promotion_codes' => $this->allowPromotionCodes, From 3e29b338c73a1f8fc7087cf28b91b56d3bbcb9db Mon Sep 17 00:00:00 2001 From: hutao Date: Wed, 8 Jan 2025 11:48:53 +0800 Subject: [PATCH 2/6] refactor: optimize code comments --- src/Checkout.php | 2 +- src/CheckoutBuilder.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Checkout.php b/src/Checkout.php index 234b99a2..b0109464 100644 --- a/src/Checkout.php +++ b/src/Checkout.php @@ -70,7 +70,7 @@ public static function customer($owner, $parentInstance = null) * @param \Illuminate\Database\Eloquent\Model|null $owner * @param array $sessionOptions * @param array $customerOptions - * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts + * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts * @return \Laravel\Cashier\Checkout */ public static function create($owner, array $sessionOptions = [], array $customerOptions = [], $opts = null) diff --git a/src/CheckoutBuilder.php b/src/CheckoutBuilder.php index 29d91a02..5f0facf1 100644 --- a/src/CheckoutBuilder.php +++ b/src/CheckoutBuilder.php @@ -64,7 +64,7 @@ public static function make($owner = null, $instance = null) * @param array|string $items * @param array $sessionOptions * @param array $customerOptions - * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts + * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts * @return \Laravel\Cashier\Checkout */ public function create($items, array $sessionOptions = [], array $customerOptions = [], $opts = null) From 24f833e67b0bf8f3f2827b21d1c1308917d3779a Mon Sep 17 00:00:00 2001 From: hutao Date: Wed, 8 Jan 2025 11:51:08 +0800 Subject: [PATCH 3/6] refactor: optimize code comments --- src/Checkout.php | 2 +- src/CheckoutBuilder.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Checkout.php b/src/Checkout.php index b0109464..48bcf149 100644 --- a/src/Checkout.php +++ b/src/Checkout.php @@ -70,7 +70,7 @@ public static function customer($owner, $parentInstance = null) * @param \Illuminate\Database\Eloquent\Model|null $owner * @param array $sessionOptions * @param array $customerOptions - * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts + * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts * @return \Laravel\Cashier\Checkout */ public static function create($owner, array $sessionOptions = [], array $customerOptions = [], $opts = null) diff --git a/src/CheckoutBuilder.php b/src/CheckoutBuilder.php index 5f0facf1..5188f8ce 100644 --- a/src/CheckoutBuilder.php +++ b/src/CheckoutBuilder.php @@ -64,7 +64,7 @@ public static function make($owner = null, $instance = null) * @param array|string $items * @param array $sessionOptions * @param array $customerOptions - * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts + * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts * @return \Laravel\Cashier\Checkout */ public function create($items, array $sessionOptions = [], array $customerOptions = [], $opts = null) From f580a9edd637cced59d5d9cde35651ad8085b9f9 Mon Sep 17 00:00:00 2001 From: hutao Date: Wed, 8 Jan 2025 11:52:45 +0800 Subject: [PATCH 4/6] refactor: optimize code comments --- src/Checkout.php | 1 + src/CheckoutBuilder.php | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Checkout.php b/src/Checkout.php index 48bcf149..9fba9acb 100644 --- a/src/Checkout.php +++ b/src/Checkout.php @@ -11,6 +11,7 @@ /** * @phpstan-import-type RequestOptionsArray from \Stripe\Util\RequestOptions + * * @psalm-import-type RequestOptionsArray from \Stripe\Util\RequestOptions */ class Checkout implements Arrayable, Jsonable, JsonSerializable, Responsable diff --git a/src/CheckoutBuilder.php b/src/CheckoutBuilder.php index 5188f8ce..b98512ad 100644 --- a/src/CheckoutBuilder.php +++ b/src/CheckoutBuilder.php @@ -8,6 +8,7 @@ /** * @phpstan-import-type RequestOptionsArray from \Stripe\Util\RequestOptions + * * @psalm-import-type RequestOptionsArray from \Stripe\Util\RequestOptions */ class CheckoutBuilder From 8341ee6fd7fcff0b7af050e55bc3e31654d91781 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Wed, 8 Jan 2025 10:58:17 +0100 Subject: [PATCH 5/6] Update src/Checkout.php --- src/Checkout.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Checkout.php b/src/Checkout.php index 9fba9acb..1c631ef4 100644 --- a/src/Checkout.php +++ b/src/Checkout.php @@ -71,7 +71,7 @@ public static function customer($owner, $parentInstance = null) * @param \Illuminate\Database\Eloquent\Model|null $owner * @param array $sessionOptions * @param array $customerOptions - * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts + * @param RequestOptionsArray|\Stripe\Util\RequestOptions|null $opts * @return \Laravel\Cashier\Checkout */ public static function create($owner, array $sessionOptions = [], array $customerOptions = [], $opts = null) From 94ea705c3138188a15f62a46fd7159a1b728a8c6 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Wed, 8 Jan 2025 10:58:38 +0100 Subject: [PATCH 6/6] Update src/CheckoutBuilder.php --- src/CheckoutBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CheckoutBuilder.php b/src/CheckoutBuilder.php index b98512ad..114fb1fd 100644 --- a/src/CheckoutBuilder.php +++ b/src/CheckoutBuilder.php @@ -65,7 +65,7 @@ public static function make($owner = null, $instance = null) * @param array|string $items * @param array $sessionOptions * @param array $customerOptions - * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts + * @param RequestOptionsArray|\Stripe\Util\RequestOptions|null $opts * @return \Laravel\Cashier\Checkout */ public function create($items, array $sessionOptions = [], array $customerOptions = [], $opts = null)