diff --git a/composer.json b/composer.json index 88f2f63..efa460f 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ ], "require": { "payum/core": "^1.6", - "stripe/stripe-php": "^9" + "stripe/stripe-php": "^12" }, "require-dev": { "phpunit/phpunit": "^8|^9", diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 1dc72d8..75d6314 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -17,17 +17,32 @@ parameters: message: '/Parameter #2 (\$arr2|\.\.\.\$replacements) of function array_replace expects array, mixed given\./' path: src/AbstractStripeGatewayFactory.php - - message: '/Parameter #[12] \$[^ ]+ of class FluxSE\\PayumStripe\\Api\\StripeCheckoutSessionApi constructor expects string, mixed given\./' + message: '/Parameter #[12] \$[^ ]+ of class FluxSE\\PayumStripe\\Api\\Stripe(CheckoutSession|Js)Api constructor expects string, mixed given\./' paths: - src/StripeCheckoutSessionGatewayFactory.php - src/StripeJsGatewayFactory.php - - message: '/Parameter #3 \$webhookSecretKeys of class FluxSE\\PayumStripe\\Api\\StripeCheckoutSessionApi constructor expects array, mixed given\./' + message: '/Parameter #3 \$webhookSecretKeys of class FluxSE\\PayumStripe\\Api\\Stripe(CheckoutSession|Js)Api constructor expects array, mixed given\./' paths: - src/StripeCheckoutSessionGatewayFactory.php - src/StripeJsGatewayFactory.php - - message: '/Parameter #4 \$paymentMethodTypes of class FluxSE\\PayumStripe\\Api\\StripeCheckoutSessionApi constructor expects array, mixed given\./' + message: '/Parameter #4 \$clientId of class FluxSE\\PayumStripe\\Api\\Stripe(CheckoutSession|Js)Api constructor expects string\|null, mixed given\./' + paths: + - src/StripeCheckoutSessionGatewayFactory.php + - src/StripeJsGatewayFactory.php + - + message: '/Parameter #5 \$stripeAccount of class FluxSE\\PayumStripe\\Api\\Stripe(CheckoutSession|Js)Api constructor expects string\|null, mixed given\./' + paths: + - src/StripeCheckoutSessionGatewayFactory.php + - src/StripeJsGatewayFactory.php + - + message: '/Parameter #6 \$stripeVersion of class FluxSE\\PayumStripe\\Api\\Stripe(CheckoutSession|Js)Api constructor expects string, mixed given\./' + paths: + - src/StripeCheckoutSessionGatewayFactory.php + - src/StripeJsGatewayFactory.php + - + message: '/Parameter #7 \$paymentMethodTypes of class FluxSE\\PayumStripe\\Api\\StripeCheckoutSessionApi constructor expects array, mixed given\./' path: src/StripeCheckoutSessionGatewayFactory.php - message: '/Parameter #1 \$templateName of class FluxSE\\PayumStripe\\Action\\StripeJs\\Api\\RenderStripeJsAction constructor expects string, mixed given\./' diff --git a/src/AbstractStripeGatewayFactory.php b/src/AbstractStripeGatewayFactory.php index beea296..e8a8654 100644 --- a/src/AbstractStripeGatewayFactory.php +++ b/src/AbstractStripeGatewayFactory.php @@ -65,6 +65,7 @@ use FluxSE\PayumStripe\Api\KeysAwareInterface; use Payum\Core\Bridge\Spl\ArrayObject; use Payum\Core\GatewayFactory; +use Stripe\Util\ApiVersion; abstract class AbstractStripeGatewayFactory extends GatewayFactory { @@ -182,6 +183,9 @@ protected function getStripeDefaultOptions(): array 'publishable_key' => '', 'secret_key' => '', 'webhook_secret_keys' => [], + 'client_id' => null, + 'stripe_account' => null, + 'stripe_version' => ApiVersion::CURRENT, ]; } diff --git a/src/Action/Api/Resource/AbstractAllAction.php b/src/Action/Api/Resource/AbstractAllAction.php index 33361b0..c76c3e0 100644 --- a/src/Action/Api/Resource/AbstractAllAction.php +++ b/src/Action/Api/Resource/AbstractAllAction.php @@ -8,9 +8,7 @@ use FluxSE\PayumStripe\Request\Api\Resource\AllInterface; use Payum\Core\Exception\LogicException; use Payum\Core\Exception\RequestNotSupportedException; -use Stripe\ApiOperations\All; use Stripe\Collection; -use Stripe\Stripe; abstract class AbstractAllAction implements AllResourceActionInterface { @@ -34,15 +32,12 @@ public function execute($request): void */ public function allApiResource(AllInterface $request): Collection { - $apiResourceClass = $this->getApiResourceClass(); - if (false === method_exists($apiResourceClass, 'all')) { - throw new LogicException(sprintf('This class "%s" is not an instance of "%s" !', $apiResourceClass, All::class)); + $service = $this->getService(); + if (false === method_exists($service, 'all')) { + throw new LogicException('This Stripe service does not have "all" method !'); } - Stripe::setApiKey($this->api->getSecretKey()); - - /* @see All::all() */ - return $apiResourceClass::all( + return $service->all( $request->getParameters(), $request->getOptions() ); diff --git a/src/Action/Api/Resource/AbstractCreateAction.php b/src/Action/Api/Resource/AbstractCreateAction.php index 4973e36..a8df798 100644 --- a/src/Action/Api/Resource/AbstractCreateAction.php +++ b/src/Action/Api/Resource/AbstractCreateAction.php @@ -8,9 +8,7 @@ use FluxSE\PayumStripe\Request\Api\Resource\CreateInterface; use Payum\Core\Exception\LogicException; use Payum\Core\Exception\RequestNotSupportedException; -use Stripe\ApiOperations\Create; use Stripe\ApiResource; -use Stripe\Stripe; abstract class AbstractCreateAction implements CreateResourceActionInterface { @@ -34,15 +32,12 @@ public function execute($request): void */ public function createApiResource(CreateInterface $request): ApiResource { - $apiResourceClass = $this->getApiResourceClass(); - if (false === method_exists($apiResourceClass, 'create')) { - throw new LogicException(sprintf('This class "%s" is not an instance of "%s" !', $apiResourceClass, Create::class)); + $service = $this->getService(); + if (false === method_exists($service, 'create')) { + throw new LogicException('This Stripe service does not have "create" method !'); } - Stripe::setApiKey($this->api->getSecretKey()); - - /* @see Create::create() */ - return $apiResourceClass::create( + return $service->create( $request->getParameters(), $request->getOptions() ); diff --git a/src/Action/Api/Resource/AbstractDeleteAction.php b/src/Action/Api/Resource/AbstractDeleteAction.php index 810dfe4..d957266 100644 --- a/src/Action/Api/Resource/AbstractDeleteAction.php +++ b/src/Action/Api/Resource/AbstractDeleteAction.php @@ -8,10 +8,7 @@ use FluxSE\PayumStripe\Request\Api\Resource\DeleteInterface; use Payum\Core\Exception\LogicException; use Payum\Core\Exception\RequestNotSupportedException; -use Stripe\ApiOperations\Delete; -use Stripe\ApiOperations\Retrieve; use Stripe\ApiResource; -use Stripe\Stripe; abstract class AbstractDeleteAction implements DeleteResourceActionInterface { @@ -32,24 +29,20 @@ public function execute($request): void public function deleteApiResource(DeleteInterface $request): ApiResource { - $apiResourceClass = $this->getApiResourceClass(); - if (false === method_exists($apiResourceClass, 'retrieve')) { - throw new LogicException(sprintf('This class "%s" is not an instance of "%s" !', $apiResourceClass, Retrieve::class)); + $service = $this->getService(); + if (false === method_exists($service, 'retrieve')) { + throw new LogicException('This Stripe service does not have "retrieve" method !'); } - if (false === method_exists($apiResourceClass, 'delete')) { - throw new LogicException(sprintf('This class "%s" is not an instance of "%s" !', $apiResourceClass, Delete::class)); + if (false === method_exists($service, 'delete')) { + throw new LogicException('This Stripe service does not have "delete" method !'); } - Stripe::setApiKey($this->api->getSecretKey()); - - /** @see Retrieve::retrieve() */ - $apiResource = $apiResourceClass::retrieve( + $apiResource = $service->retrieve( $request->getId(), $request->getOptions() ); - /* @see Delete::delete() */ return $apiResource->delete(); } diff --git a/src/Action/Api/Resource/AbstractRetrieveAction.php b/src/Action/Api/Resource/AbstractRetrieveAction.php index 25cf0b1..04901fb 100644 --- a/src/Action/Api/Resource/AbstractRetrieveAction.php +++ b/src/Action/Api/Resource/AbstractRetrieveAction.php @@ -8,9 +8,7 @@ use FluxSE\PayumStripe\Request\Api\Resource\RetrieveInterface; use Payum\Core\Exception\LogicException; use Payum\Core\Exception\RequestNotSupportedException; -use Stripe\ApiOperations\Retrieve; use Stripe\ApiResource; -use Stripe\Stripe; abstract class AbstractRetrieveAction implements RetrieveResourceActionInterface { @@ -31,15 +29,12 @@ public function execute($request): void public function retrieveApiResource(RetrieveInterface $request): ApiResource { - $apiResourceClass = $this->getApiResourceClass(); - if (false === method_exists($apiResourceClass, 'retrieve')) { - throw new LogicException(sprintf('This class "%s" is not an instance of "%s" !', $apiResourceClass, Retrieve::class)); + $service = $this->getService(); + if (false === method_exists($service, 'retrieve')) { + throw new LogicException('This Stripe service does not have "retrieve" method !'); } - Stripe::setApiKey($this->api->getSecretKey()); - - /* @see Retrieve::retrieve() */ - return $apiResourceClass::retrieve( + return $service->retrieve( $request->getId(), $request->getOptions() ); diff --git a/src/Action/Api/Resource/AbstractUpdateAction.php b/src/Action/Api/Resource/AbstractUpdateAction.php index eeb88b5..bdbe2c3 100644 --- a/src/Action/Api/Resource/AbstractUpdateAction.php +++ b/src/Action/Api/Resource/AbstractUpdateAction.php @@ -8,9 +8,7 @@ use FluxSE\PayumStripe\Request\Api\Resource\UpdateInterface; use Payum\Core\Exception\LogicException; use Payum\Core\Exception\RequestNotSupportedException; -use Stripe\ApiOperations\Update; use Stripe\ApiResource; -use Stripe\Stripe; abstract class AbstractUpdateAction implements UpdateResourceActionInterface { @@ -31,15 +29,13 @@ public function execute($request): void public function updateApiResource(UpdateInterface $request): ApiResource { - $apiResourceClass = $this->getApiResourceClass(); - if (false === method_exists($apiResourceClass, 'update')) { - throw new LogicException(sprintf('This class "%s" is not an instance of "%s" !', $apiResourceClass, Update::class)); - } + $service = $this->getService(); - Stripe::setApiKey($this->api->getSecretKey()); + if (false === method_exists($service, 'update')) { + throw new LogicException('This Stripe service does not have "update" method !'); + } - /* @see Update::update() */ - return $apiResourceClass::update( + return $service->update( $request->getId(), $request->getParameters(), $request->getOptions() diff --git a/src/Action/Api/Resource/AllCouponAction.php b/src/Action/Api/Resource/AllCouponAction.php index 60b839b..2402fe4 100644 --- a/src/Action/Api/Resource/AllCouponAction.php +++ b/src/Action/Api/Resource/AllCouponAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\AllCoupon; use FluxSE\PayumStripe\Request\Api\Resource\AllInterface; -use Stripe\Coupon; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class AllCouponAction extends AbstractAllAction { - protected $apiResourceClass = Coupon::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->coupons; + } public function supportAlso(AllInterface $request): bool { diff --git a/src/Action/Api/Resource/AllCustomerAction.php b/src/Action/Api/Resource/AllCustomerAction.php index 6532d5b..eeda501 100644 --- a/src/Action/Api/Resource/AllCustomerAction.php +++ b/src/Action/Api/Resource/AllCustomerAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\AllCustomer; use FluxSE\PayumStripe\Request\Api\Resource\AllInterface; -use Stripe\Customer; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class AllCustomerAction extends AbstractAllAction { - protected $apiResourceClass = Customer::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->customers; + } public function supportAlso(AllInterface $request): bool { diff --git a/src/Action/Api/Resource/AllInvoiceAction.php b/src/Action/Api/Resource/AllInvoiceAction.php index 1d6a0aa..9eec7b4 100644 --- a/src/Action/Api/Resource/AllInvoiceAction.php +++ b/src/Action/Api/Resource/AllInvoiceAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\AllInterface; use FluxSE\PayumStripe\Request\Api\Resource\AllInvoice; -use Stripe\Invoice; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class AllInvoiceAction extends AbstractAllAction { - protected $apiResourceClass = Invoice::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->invoices; + } public function supportAlso(AllInterface $request): bool { diff --git a/src/Action/Api/Resource/AllPlanAction.php b/src/Action/Api/Resource/AllPlanAction.php new file mode 100644 index 0000000..29ab92c --- /dev/null +++ b/src/Action/Api/Resource/AllPlanAction.php @@ -0,0 +1,23 @@ +plans; + } + + public function supportAlso(AllInterface $request): bool + { + return $request instanceof AllPlan; + } +} diff --git a/src/Action/Api/Resource/AllPriceAction.php b/src/Action/Api/Resource/AllPriceAction.php new file mode 100644 index 0000000..8383a3c --- /dev/null +++ b/src/Action/Api/Resource/AllPriceAction.php @@ -0,0 +1,23 @@ +prices; + } + + public function supportAlso(AllInterface $request): bool + { + return $request instanceof AllPrice; + } +} diff --git a/src/Action/Api/Resource/AllProductAction.php b/src/Action/Api/Resource/AllProductAction.php new file mode 100644 index 0000000..f2fd34b --- /dev/null +++ b/src/Action/Api/Resource/AllProductAction.php @@ -0,0 +1,23 @@ +products; + } + + public function supportAlso(AllInterface $request): bool + { + return $request instanceof AllProduct; + } +} diff --git a/src/Action/Api/Resource/AllSessionAction.php b/src/Action/Api/Resource/AllSessionAction.php index e0e0800..dfd86f1 100644 --- a/src/Action/Api/Resource/AllSessionAction.php +++ b/src/Action/Api/Resource/AllSessionAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\AllInterface; use FluxSE\PayumStripe\Request\Api\Resource\AllSession; -use Stripe\Checkout\Session; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class AllSessionAction extends AbstractAllAction { - protected $apiResourceClass = Session::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->checkout->sessions; + } public function supportAlso(AllInterface $request): bool { diff --git a/src/Action/Api/Resource/AllTaxRateAction.php b/src/Action/Api/Resource/AllTaxRateAction.php index 0f1232d..819f835 100644 --- a/src/Action/Api/Resource/AllTaxRateAction.php +++ b/src/Action/Api/Resource/AllTaxRateAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\AllInterface; use FluxSE\PayumStripe\Request\Api\Resource\AllTaxRate; -use Stripe\TaxRate; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class AllTaxRateAction extends AbstractAllAction { - protected $apiResourceClass = TaxRate::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->taxRates; + } public function supportAlso(AllInterface $request): bool { diff --git a/src/Action/Api/Resource/CancelPaymentIntentAction.php b/src/Action/Api/Resource/CancelPaymentIntentAction.php index 01fdd51..be0f7c3 100644 --- a/src/Action/Api/Resource/CancelPaymentIntentAction.php +++ b/src/Action/Api/Resource/CancelPaymentIntentAction.php @@ -9,10 +9,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\RetrieveInterface; use Stripe\ApiResource; use Stripe\PaymentIntent; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class CancelPaymentIntentAction extends AbstractRetrieveAction { - protected $apiResourceClass = PaymentIntent::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->paymentIntents; + } public function supportAlso(RetrieveInterface $request): bool { diff --git a/src/Action/Api/Resource/CancelSetupIntentAction.php b/src/Action/Api/Resource/CancelSetupIntentAction.php index 7b431b1..5f5a75f 100644 --- a/src/Action/Api/Resource/CancelSetupIntentAction.php +++ b/src/Action/Api/Resource/CancelSetupIntentAction.php @@ -8,11 +8,16 @@ use FluxSE\PayumStripe\Request\Api\Resource\CustomCallInterface; use FluxSE\PayumStripe\Request\Api\Resource\RetrieveInterface; use Stripe\ApiResource; +use Stripe\Service\AbstractService; use Stripe\SetupIntent; +use Stripe\StripeClient; final class CancelSetupIntentAction extends AbstractRetrieveAction { - protected $apiResourceClass = SetupIntent::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->setupIntents; + } public function supportAlso(RetrieveInterface $request): bool { diff --git a/src/Action/Api/Resource/CancelSubscriptionAction.php b/src/Action/Api/Resource/CancelSubscriptionAction.php index 93753b4..049ba5e 100644 --- a/src/Action/Api/Resource/CancelSubscriptionAction.php +++ b/src/Action/Api/Resource/CancelSubscriptionAction.php @@ -8,11 +8,16 @@ use FluxSE\PayumStripe\Request\Api\Resource\CustomCallInterface; use FluxSE\PayumStripe\Request\Api\Resource\RetrieveInterface; use Stripe\ApiResource; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; use Stripe\Subscription; final class CancelSubscriptionAction extends AbstractRetrieveAction { - protected $apiResourceClass = Subscription::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->subscriptions; + } public function supportAlso(RetrieveInterface $request): bool { diff --git a/src/Action/Api/Resource/CapturePaymentIntentAction.php b/src/Action/Api/Resource/CapturePaymentIntentAction.php index 8b362b4..5480dce 100644 --- a/src/Action/Api/Resource/CapturePaymentIntentAction.php +++ b/src/Action/Api/Resource/CapturePaymentIntentAction.php @@ -9,10 +9,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\RetrieveInterface; use Stripe\ApiResource; use Stripe\PaymentIntent; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class CapturePaymentIntentAction extends AbstractRetrieveAction { - protected $apiResourceClass = PaymentIntent::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->paymentIntents; + } public function supportAlso(RetrieveInterface $request): bool { diff --git a/src/Action/Api/Resource/CreateCouponAction.php b/src/Action/Api/Resource/CreateCouponAction.php index 678ec3c..138e2b8 100644 --- a/src/Action/Api/Resource/CreateCouponAction.php +++ b/src/Action/Api/Resource/CreateCouponAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\CreateCoupon; use FluxSE\PayumStripe\Request\Api\Resource\CreateInterface; -use Stripe\Coupon; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class CreateCouponAction extends AbstractCreateAction { - protected $apiResourceClass = Coupon::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->coupons; + } public function supportAlso(CreateInterface $request): bool { diff --git a/src/Action/Api/Resource/CreateCustomerAction.php b/src/Action/Api/Resource/CreateCustomerAction.php index 01e8473..7941336 100644 --- a/src/Action/Api/Resource/CreateCustomerAction.php +++ b/src/Action/Api/Resource/CreateCustomerAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\CreateCustomer; use FluxSE\PayumStripe\Request\Api\Resource\CreateInterface; -use Stripe\Customer; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class CreateCustomerAction extends AbstractCreateAction { - protected $apiResourceClass = Customer::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->customers; + } public function supportAlso(CreateInterface $request): bool { diff --git a/src/Action/Api/Resource/CreatePaymentIntentAction.php b/src/Action/Api/Resource/CreatePaymentIntentAction.php index 11dd76a..d0e382f 100644 --- a/src/Action/Api/Resource/CreatePaymentIntentAction.php +++ b/src/Action/Api/Resource/CreatePaymentIntentAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\CreateInterface; use FluxSE\PayumStripe\Request\Api\Resource\CreatePaymentIntent; -use Stripe\PaymentIntent; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class CreatePaymentIntentAction extends AbstractCreateAction { - protected $apiResourceClass = PaymentIntent::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->paymentIntents; + } public function supportAlso(CreateInterface $request): bool { diff --git a/src/Action/Api/Resource/CreatePaymentMethodAction.php b/src/Action/Api/Resource/CreatePaymentMethodAction.php index dc3331c..82c7b48 100644 --- a/src/Action/Api/Resource/CreatePaymentMethodAction.php +++ b/src/Action/Api/Resource/CreatePaymentMethodAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\CreateInterface; use FluxSE\PayumStripe\Request\Api\Resource\CreatePaymentMethod; -use Stripe\PaymentMethod; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class CreatePaymentMethodAction extends AbstractCreateAction { - protected $apiResourceClass = PaymentMethod::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->paymentMethods; + } public function supportAlso(CreateInterface $request): bool { diff --git a/src/Action/Api/Resource/CreatePlanAction.php b/src/Action/Api/Resource/CreatePlanAction.php index 36bf0db..7f638dd 100644 --- a/src/Action/Api/Resource/CreatePlanAction.php +++ b/src/Action/Api/Resource/CreatePlanAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\CreateInterface; use FluxSE\PayumStripe\Request\Api\Resource\CreatePlan; -use Stripe\Plan; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class CreatePlanAction extends AbstractCreateAction { - protected $apiResourceClass = Plan::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->plans; + } public function supportAlso(CreateInterface $request): bool { diff --git a/src/Action/Api/Resource/CreatePriceAction.php b/src/Action/Api/Resource/CreatePriceAction.php new file mode 100644 index 0000000..eafd63a --- /dev/null +++ b/src/Action/Api/Resource/CreatePriceAction.php @@ -0,0 +1,23 @@ +prices; + } + + public function supportAlso(CreateInterface $request): bool + { + return $request instanceof CreatePrice; + } +} diff --git a/src/Action/Api/Resource/CreateProductAction.php b/src/Action/Api/Resource/CreateProductAction.php new file mode 100644 index 0000000..a5e1ecc --- /dev/null +++ b/src/Action/Api/Resource/CreateProductAction.php @@ -0,0 +1,23 @@ +products; + } + + public function supportAlso(CreateInterface $request): bool + { + return $request instanceof CreateProduct; + } +} diff --git a/src/Action/Api/Resource/CreateRefundAction.php b/src/Action/Api/Resource/CreateRefundAction.php index 9ba6988..7a58512 100644 --- a/src/Action/Api/Resource/CreateRefundAction.php +++ b/src/Action/Api/Resource/CreateRefundAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\CreateInterface; use FluxSE\PayumStripe\Request\Api\Resource\CreateRefund; -use Stripe\Refund; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class CreateRefundAction extends AbstractCreateAction { - protected $apiResourceClass = Refund::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->refunds; + } public function supportAlso(CreateInterface $request): bool { diff --git a/src/Action/Api/Resource/CreateSessionAction.php b/src/Action/Api/Resource/CreateSessionAction.php index 2ab2b44..972fdb9 100644 --- a/src/Action/Api/Resource/CreateSessionAction.php +++ b/src/Action/Api/Resource/CreateSessionAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\CreateInterface; use FluxSE\PayumStripe\Request\Api\Resource\CreateSession; -use Stripe\Checkout\Session; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class CreateSessionAction extends AbstractCreateAction { - protected $apiResourceClass = Session::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->checkout->sessions; + } public function supportAlso(CreateInterface $request): bool { diff --git a/src/Action/Api/Resource/CreateSetupIntentAction.php b/src/Action/Api/Resource/CreateSetupIntentAction.php index 262084f..1de570b 100644 --- a/src/Action/Api/Resource/CreateSetupIntentAction.php +++ b/src/Action/Api/Resource/CreateSetupIntentAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\CreateInterface; use FluxSE\PayumStripe\Request\Api\Resource\CreateSetupIntent; -use Stripe\SetupIntent; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class CreateSetupIntentAction extends AbstractCreateAction { - protected $apiResourceClass = SetupIntent::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->setupIntents; + } public function supportAlso(CreateInterface $request): bool { diff --git a/src/Action/Api/Resource/CreateSubscriptionAction.php b/src/Action/Api/Resource/CreateSubscriptionAction.php index 8bc4ef4..65b7638 100644 --- a/src/Action/Api/Resource/CreateSubscriptionAction.php +++ b/src/Action/Api/Resource/CreateSubscriptionAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\CreateInterface; use FluxSE\PayumStripe\Request\Api\Resource\CreateSubscription; -use Stripe\Subscription; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class CreateSubscriptionAction extends AbstractCreateAction { - protected $apiResourceClass = Subscription::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->subscriptions; + } public function supportAlso(CreateInterface $request): bool { diff --git a/src/Action/Api/Resource/CreateTaxRateAction.php b/src/Action/Api/Resource/CreateTaxRateAction.php index 6519d84..dcb1c17 100644 --- a/src/Action/Api/Resource/CreateTaxRateAction.php +++ b/src/Action/Api/Resource/CreateTaxRateAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\CreateInterface; use FluxSE\PayumStripe\Request\Api\Resource\CreateTaxRate; -use Stripe\TaxRate; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class CreateTaxRateAction extends AbstractCreateAction { - protected $apiResourceClass = TaxRate::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->taxRates; + } public function supportAlso(CreateInterface $request): bool { diff --git a/src/Action/Api/Resource/DeleteCouponAction.php b/src/Action/Api/Resource/DeleteCouponAction.php index d0cc6c1..ca48405 100644 --- a/src/Action/Api/Resource/DeleteCouponAction.php +++ b/src/Action/Api/Resource/DeleteCouponAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\DeleteCoupon; use FluxSE\PayumStripe\Request\Api\Resource\DeleteInterface; -use Stripe\Coupon; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class DeleteCouponAction extends AbstractDeleteAction { - protected $apiResourceClass = Coupon::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->coupons; + } public function supportAlso(DeleteInterface $request): bool { diff --git a/src/Action/Api/Resource/DeletePlanAction.php b/src/Action/Api/Resource/DeletePlanAction.php index 7554a4f..fadd1de 100644 --- a/src/Action/Api/Resource/DeletePlanAction.php +++ b/src/Action/Api/Resource/DeletePlanAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\DeleteInterface; use FluxSE\PayumStripe\Request\Api\Resource\DeletePlan; -use Stripe\Plan; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class DeletePlanAction extends AbstractDeleteAction { - protected $apiResourceClass = Plan::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->plans; + } public function supportAlso(DeleteInterface $request): bool { diff --git a/src/Action/Api/Resource/DeleteProductAction.php b/src/Action/Api/Resource/DeleteProductAction.php new file mode 100644 index 0000000..ddab51c --- /dev/null +++ b/src/Action/Api/Resource/DeleteProductAction.php @@ -0,0 +1,23 @@ +products; + } + + public function supportAlso(DeleteInterface $request): bool + { + return $request instanceof DeleteProduct; + } +} diff --git a/src/Action/Api/Resource/ExpireSessionAction.php b/src/Action/Api/Resource/ExpireSessionAction.php index 47e56f9..e603c33 100644 --- a/src/Action/Api/Resource/ExpireSessionAction.php +++ b/src/Action/Api/Resource/ExpireSessionAction.php @@ -9,10 +9,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\RetrieveInterface; use Stripe\ApiResource; use Stripe\Checkout\Session; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class ExpireSessionAction extends AbstractRetrieveAction { - protected $apiResourceClass = Session::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->checkout->sessions; + } public function supportAlso(RetrieveInterface $request): bool { diff --git a/src/Action/Api/Resource/ResourceActionInterface.php b/src/Action/Api/Resource/ResourceActionInterface.php index 4fe6b45..d8419d7 100644 --- a/src/Action/Api/Resource/ResourceActionInterface.php +++ b/src/Action/Api/Resource/ResourceActionInterface.php @@ -6,10 +6,10 @@ use Payum\Core\Action\ActionInterface; use Payum\Core\ApiAwareInterface; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; interface ResourceActionInterface extends ActionInterface, ApiAwareInterface { - public function getApiResourceClass(): string; - - public function setApiResourceClass(string $apiResourceClass): void; + public function getStripeService(StripeClient $stripeClient): AbstractService; } diff --git a/src/Action/Api/Resource/ResourceAwareActionTrait.php b/src/Action/Api/Resource/ResourceAwareActionTrait.php index 60c69ea..327ed0f 100644 --- a/src/Action/Api/Resource/ResourceAwareActionTrait.php +++ b/src/Action/Api/Resource/ResourceAwareActionTrait.php @@ -4,18 +4,24 @@ namespace FluxSE\PayumStripe\Action\Api\Resource; +use FluxSE\PayumStripe\Api\StripeClientAwareInterface; +use Payum\Core\Exception\LogicException; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; + +/** + * @property StripeClientAwareInterface $api + */ trait ResourceAwareActionTrait { - /** @var string */ - protected $apiResourceClass = ''; + abstract public function getStripeService(StripeClient $stripeClient): AbstractService; - public function getApiResourceClass(): string + protected function getService(): AbstractService { - return $this->apiResourceClass; - } + if (null === $this->api) { + throw new LogicException('Api class not found !'); + } - public function setApiResourceClass(string $apiResourceClass): void - { - $this->apiResourceClass = $apiResourceClass; + return $this->getStripeService($this->api->getStripeClient()); } } diff --git a/src/Action/Api/Resource/RetrieveChargeAction.php b/src/Action/Api/Resource/RetrieveChargeAction.php index 6f9f235..6662d3e 100644 --- a/src/Action/Api/Resource/RetrieveChargeAction.php +++ b/src/Action/Api/Resource/RetrieveChargeAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\RetrieveCharge; use FluxSE\PayumStripe\Request\Api\Resource\RetrieveInterface; -use Stripe\Charge; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class RetrieveChargeAction extends AbstractRetrieveAction { - protected $apiResourceClass = Charge::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->charges; + } public function supportAlso(RetrieveInterface $request): bool { diff --git a/src/Action/Api/Resource/RetrieveCouponAction.php b/src/Action/Api/Resource/RetrieveCouponAction.php index 72431b7..e18ebc8 100644 --- a/src/Action/Api/Resource/RetrieveCouponAction.php +++ b/src/Action/Api/Resource/RetrieveCouponAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\RetrieveCoupon; use FluxSE\PayumStripe\Request\Api\Resource\RetrieveInterface; -use Stripe\Coupon; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class RetrieveCouponAction extends AbstractRetrieveAction { - protected $apiResourceClass = Coupon::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->coupons; + } public function supportAlso(RetrieveInterface $request): bool { diff --git a/src/Action/Api/Resource/RetrieveCustomerAction.php b/src/Action/Api/Resource/RetrieveCustomerAction.php index e8a5e5c..0025111 100644 --- a/src/Action/Api/Resource/RetrieveCustomerAction.php +++ b/src/Action/Api/Resource/RetrieveCustomerAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\RetrieveCustomer; use FluxSE\PayumStripe\Request\Api\Resource\RetrieveInterface; -use Stripe\Customer; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class RetrieveCustomerAction extends AbstractRetrieveAction { - protected $apiResourceClass = Customer::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->customers; + } public function supportAlso(RetrieveInterface $request): bool { diff --git a/src/Action/Api/Resource/RetrieveInvoiceAction.php b/src/Action/Api/Resource/RetrieveInvoiceAction.php index cc684d5..22687fa 100644 --- a/src/Action/Api/Resource/RetrieveInvoiceAction.php +++ b/src/Action/Api/Resource/RetrieveInvoiceAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\RetrieveInterface; use FluxSE\PayumStripe\Request\Api\Resource\RetrieveInvoice; -use Stripe\Invoice; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class RetrieveInvoiceAction extends AbstractRetrieveAction { - protected $apiResourceClass = Invoice::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->invoices; + } public function supportAlso(RetrieveInterface $request): bool { diff --git a/src/Action/Api/Resource/RetrievePaymentIntentAction.php b/src/Action/Api/Resource/RetrievePaymentIntentAction.php index 4f01ac0..ba962a8 100644 --- a/src/Action/Api/Resource/RetrievePaymentIntentAction.php +++ b/src/Action/Api/Resource/RetrievePaymentIntentAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\RetrieveInterface; use FluxSE\PayumStripe\Request\Api\Resource\RetrievePaymentIntent; -use Stripe\PaymentIntent; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class RetrievePaymentIntentAction extends AbstractRetrieveAction { - protected $apiResourceClass = PaymentIntent::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->paymentIntents; + } public function supportAlso(RetrieveInterface $request): bool { diff --git a/src/Action/Api/Resource/RetrievePaymentMethodAction.php b/src/Action/Api/Resource/RetrievePaymentMethodAction.php index 35ac30f..527f005 100644 --- a/src/Action/Api/Resource/RetrievePaymentMethodAction.php +++ b/src/Action/Api/Resource/RetrievePaymentMethodAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\RetrieveInterface; use FluxSE\PayumStripe\Request\Api\Resource\RetrievePaymentMethod; -use Stripe\PaymentMethod; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class RetrievePaymentMethodAction extends AbstractRetrieveAction { - protected $apiResourceClass = PaymentMethod::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->paymentMethods; + } public function supportAlso(RetrieveInterface $request): bool { diff --git a/src/Action/Api/Resource/RetrievePlanAction.php b/src/Action/Api/Resource/RetrievePlanAction.php index a683f51..1aee8ad 100644 --- a/src/Action/Api/Resource/RetrievePlanAction.php +++ b/src/Action/Api/Resource/RetrievePlanAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\RetrieveInterface; use FluxSE\PayumStripe\Request\Api\Resource\RetrievePlan; -use Stripe\Plan; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class RetrievePlanAction extends AbstractRetrieveAction { - protected $apiResourceClass = Plan::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->plans; + } public function supportAlso(RetrieveInterface $request): bool { diff --git a/src/Action/Api/Resource/RetrievePriceAction.php b/src/Action/Api/Resource/RetrievePriceAction.php new file mode 100644 index 0000000..a1d75f1 --- /dev/null +++ b/src/Action/Api/Resource/RetrievePriceAction.php @@ -0,0 +1,23 @@ +prices; + } + + public function supportAlso(RetrieveInterface $request): bool + { + return $request instanceof RetrievePrice; + } +} diff --git a/src/Action/Api/Resource/RetrieveProductAction.php b/src/Action/Api/Resource/RetrieveProductAction.php index a818354..22201ad 100644 --- a/src/Action/Api/Resource/RetrieveProductAction.php +++ b/src/Action/Api/Resource/RetrieveProductAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\RetrieveInterface; use FluxSE\PayumStripe\Request\Api\Resource\RetrieveProduct; -use Stripe\Product; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class RetrieveProductAction extends AbstractRetrieveAction { - protected $apiResourceClass = Product::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->products; + } public function supportAlso(RetrieveInterface $request): bool { diff --git a/src/Action/Api/Resource/RetrieveSessionAction.php b/src/Action/Api/Resource/RetrieveSessionAction.php index 442d062..004083c 100644 --- a/src/Action/Api/Resource/RetrieveSessionAction.php +++ b/src/Action/Api/Resource/RetrieveSessionAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\RetrieveInterface; use FluxSE\PayumStripe\Request\Api\Resource\RetrieveSession; -use Stripe\Checkout\Session; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class RetrieveSessionAction extends AbstractRetrieveAction { - protected $apiResourceClass = Session::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->checkout->sessions; + } public function supportAlso(RetrieveInterface $request): bool { diff --git a/src/Action/Api/Resource/RetrieveSetupIntentAction.php b/src/Action/Api/Resource/RetrieveSetupIntentAction.php index 7135d2d..459b576 100644 --- a/src/Action/Api/Resource/RetrieveSetupIntentAction.php +++ b/src/Action/Api/Resource/RetrieveSetupIntentAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\RetrieveInterface; use FluxSE\PayumStripe\Request\Api\Resource\RetrieveSetupIntent; -use Stripe\SetupIntent; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class RetrieveSetupIntentAction extends AbstractRetrieveAction { - protected $apiResourceClass = SetupIntent::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->setupIntents; + } public function supportAlso(RetrieveInterface $request): bool { diff --git a/src/Action/Api/Resource/RetrieveSubscriptionAction.php b/src/Action/Api/Resource/RetrieveSubscriptionAction.php index f2b8f78..c40f586 100644 --- a/src/Action/Api/Resource/RetrieveSubscriptionAction.php +++ b/src/Action/Api/Resource/RetrieveSubscriptionAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\RetrieveInterface; use FluxSE\PayumStripe\Request\Api\Resource\RetrieveSubscription; -use Stripe\Subscription; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class RetrieveSubscriptionAction extends AbstractRetrieveAction { - protected $apiResourceClass = Subscription::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->subscriptions; + } public function supportAlso(RetrieveInterface $request): bool { diff --git a/src/Action/Api/Resource/UpdateCouponAction.php b/src/Action/Api/Resource/UpdateCouponAction.php index 60acd44..74fe45a 100644 --- a/src/Action/Api/Resource/UpdateCouponAction.php +++ b/src/Action/Api/Resource/UpdateCouponAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\UpdateCoupon; use FluxSE\PayumStripe\Request\Api\Resource\UpdateInterface; -use Stripe\Coupon; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class UpdateCouponAction extends AbstractUpdateAction { - protected $apiResourceClass = Coupon::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->coupons; + } public function supportAlso(UpdateInterface $request): bool { diff --git a/src/Action/Api/Resource/UpdatePaymentIntentAction.php b/src/Action/Api/Resource/UpdatePaymentIntentAction.php index be74308..fe73e18 100644 --- a/src/Action/Api/Resource/UpdatePaymentIntentAction.php +++ b/src/Action/Api/Resource/UpdatePaymentIntentAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\UpdateInterface; use FluxSE\PayumStripe\Request\Api\Resource\UpdatePaymentIntent; -use Stripe\PaymentIntent; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class UpdatePaymentIntentAction extends AbstractUpdateAction { - protected $apiResourceClass = PaymentIntent::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->paymentIntents; + } public function supportAlso(UpdateInterface $request): bool { diff --git a/src/Action/Api/Resource/UpdatePlanAction.php b/src/Action/Api/Resource/UpdatePlanAction.php new file mode 100644 index 0000000..6d320b9 --- /dev/null +++ b/src/Action/Api/Resource/UpdatePlanAction.php @@ -0,0 +1,23 @@ +plans; + } + + public function supportAlso(UpdateInterface $request): bool + { + return $request instanceof UpdatePlan; + } +} diff --git a/src/Action/Api/Resource/UpdatePriceAction.php b/src/Action/Api/Resource/UpdatePriceAction.php new file mode 100644 index 0000000..6734ae1 --- /dev/null +++ b/src/Action/Api/Resource/UpdatePriceAction.php @@ -0,0 +1,23 @@ +prices; + } + + public function supportAlso(UpdateInterface $request): bool + { + return $request instanceof UpdatePrice; + } +} diff --git a/src/Action/Api/Resource/UpdateProductAction.php b/src/Action/Api/Resource/UpdateProductAction.php new file mode 100644 index 0000000..19252aa --- /dev/null +++ b/src/Action/Api/Resource/UpdateProductAction.php @@ -0,0 +1,23 @@ +products; + } + + public function supportAlso(UpdateInterface $request): bool + { + return $request instanceof UpdateProduct; + } +} diff --git a/src/Action/Api/Resource/UpdateSubscriptionAction.php b/src/Action/Api/Resource/UpdateSubscriptionAction.php index 781dba7..563e9cd 100644 --- a/src/Action/Api/Resource/UpdateSubscriptionAction.php +++ b/src/Action/Api/Resource/UpdateSubscriptionAction.php @@ -6,11 +6,15 @@ use FluxSE\PayumStripe\Request\Api\Resource\UpdateInterface; use FluxSE\PayumStripe\Request\Api\Resource\UpdateSubscription; -use Stripe\Subscription; +use Stripe\Service\AbstractService; +use Stripe\StripeClient; final class UpdateSubscriptionAction extends AbstractUpdateAction { - protected $apiResourceClass = Subscription::class; + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return $stripeClient->subscriptions; + } public function supportAlso(UpdateInterface $request): bool { diff --git a/src/Action/Api/StripeApiAwareTrait.php b/src/Action/Api/StripeApiAwareTrait.php index 8292933..80eaa8d 100644 --- a/src/Action/Api/StripeApiAwareTrait.php +++ b/src/Action/Api/StripeApiAwareTrait.php @@ -4,11 +4,11 @@ namespace FluxSE\PayumStripe\Action\Api; -use FluxSE\PayumStripe\Api\KeysAwareInterface; +use FluxSE\PayumStripe\Api\StripeClientAwareInterface; use Payum\Core\ApiAwareTrait; /** - * @property KeysAwareInterface $api + * @property StripeClientAwareInterface $api */ trait StripeApiAwareTrait { @@ -21,7 +21,7 @@ public function __construct() protected function initApiClass(): void { - $this->apiClass = KeysAwareInterface::class; + $this->apiClass = StripeClientAwareInterface::class; } /** diff --git a/src/Api/KeysAwareTrait.php b/src/Api/KeysAwareTrait.php index e655c27..d51d802 100644 --- a/src/Api/KeysAwareTrait.php +++ b/src/Api/KeysAwareTrait.php @@ -8,8 +8,10 @@ trait KeysAwareTrait { /** @var string[] */ private $webhookSecretKeys; + /** @var string */ private $publishable; + /** @var string */ private $secret; @@ -43,7 +45,7 @@ public function getWebhookSecretKeys(): array public function hasWebhookSecretKey(string $webhookSecretKey): bool { - return in_array($webhookSecretKey, $this->webhookSecretKeys); + return in_array($webhookSecretKey, $this->webhookSecretKeys, true); } public function addWebhookSecretKey(string $webhookSecretKey): void diff --git a/src/Api/StripeCheckoutSessionApi.php b/src/Api/StripeCheckoutSessionApi.php index 74f5a35..7d56018 100644 --- a/src/Api/StripeCheckoutSessionApi.php +++ b/src/Api/StripeCheckoutSessionApi.php @@ -4,10 +4,12 @@ namespace FluxSE\PayumStripe\Api; +use Stripe\Util\ApiVersion; + final class StripeCheckoutSessionApi implements StripeCheckoutSessionApiInterface { - use KeysAwareTrait { - KeysAwareTrait::__construct as private __keysAwareTraitConstruct; + use StripeClientAwareTrait { + StripeClientAwareTrait::__construct as private __stripeClientAwareTraitConstruct; } use PaymentMethodTypesAwareTrait { @@ -21,9 +23,19 @@ public function __construct( string $publishable, string $secret, array $webhookSecretKeys = [], + ?string $clientId = null, + ?string $stripeAccount = null, + string $stripeVersion = ApiVersion::CURRENT, array $paymentMethodTypes = self::DEFAULT_PAYMENT_METHOD_TYPES ) { - $this->__keysAwareTraitConstruct($publishable, $secret, $webhookSecretKeys); + $this->__stripeClientAwareTraitConstruct( + $publishable, + $secret, + $webhookSecretKeys, + $clientId, + $stripeAccount, + $stripeVersion + ); $this->__paymentMethodTypesAwareTraitConstruct($paymentMethodTypes); } } diff --git a/src/Api/StripeCheckoutSessionApiInterface.php b/src/Api/StripeCheckoutSessionApiInterface.php index 2571d15..764dab1 100644 --- a/src/Api/StripeCheckoutSessionApiInterface.php +++ b/src/Api/StripeCheckoutSessionApiInterface.php @@ -4,7 +4,7 @@ namespace FluxSE\PayumStripe\Api; -interface StripeCheckoutSessionApiInterface extends KeysAwareInterface, PaymentMethodTypesAwareInterface +interface StripeCheckoutSessionApiInterface extends StripeClientAwareInterface, PaymentMethodTypesAwareInterface { public const DEFAULT_PAYMENT_METHOD_TYPES = []; } diff --git a/src/Api/StripeClientAwareInterface.php b/src/Api/StripeClientAwareInterface.php new file mode 100644 index 0000000..c08d5f4 --- /dev/null +++ b/src/Api/StripeClientAwareInterface.php @@ -0,0 +1,12 @@ +__keysAwareTraitConstruct($publishable, $secret, $webhookSecretKeys); + $this->clientId = $clientId; + $this->stripeAccount = $stripeAccount; + $this->stripeVersion = $stripeVersion; + } + + public function getStripeClient(): StripeClient + { + if (null === $this->stripeClient) { + $this->stripeClient = new StripeClient([ + 'api_key' => $this->getSecretKey(), + 'client_id' => $this->getClientId(), + 'stripe_account' => $this->getStripeAccount(), + 'stripe_version' => $this->getStripeVersion(), + ]); + } + + return $this->stripeClient; + } + + public function getClientId(): ?string + { + return $this->clientId; + } + + public function getStripeAccount(): ?string + { + return $this->stripeAccount; + } + + public function getStripeVersion(): string + { + return $this->stripeVersion; + } +} diff --git a/src/Api/StripeJsApi.php b/src/Api/StripeJsApi.php index 77551aa..a6fcfdd 100644 --- a/src/Api/StripeJsApi.php +++ b/src/Api/StripeJsApi.php @@ -6,5 +6,5 @@ final class StripeJsApi implements StripeJsApiInterface { - use KeysAwareTrait; + use StripeClientAwareTrait; } diff --git a/src/Api/StripeJsApiInterface.php b/src/Api/StripeJsApiInterface.php index 146b9cd..9aa7106 100644 --- a/src/Api/StripeJsApiInterface.php +++ b/src/Api/StripeJsApiInterface.php @@ -4,6 +4,6 @@ namespace FluxSE\PayumStripe\Api; -interface StripeJsApiInterface extends KeysAwareInterface +interface StripeJsApiInterface extends StripeClientAwareInterface { } diff --git a/src/Request/Api/Resource/AllPlan.php b/src/Request/Api/Resource/AllPlan.php new file mode 100644 index 0000000..c6b79df --- /dev/null +++ b/src/Request/Api/Resource/AllPlan.php @@ -0,0 +1,9 @@ +createMock($this->getApiClass()); - if ($shouldGetSecretKey) { - $apiMock - ->expects($this->atLeastOnce()) - ->method('getSecretKey') - ->willReturn('sk_test_123') - ; - } + $apiMock + ->method('getStripeClient') + ->willReturn($stripeClient) + ; return $apiMock; } protected function getApiClass(): string { - return KeysAwareInterface::class; + return StripeClientAwareInterface::class; } } diff --git a/tests/Action/Api/ResolveWebhookEventActionTest.php b/tests/Action/Api/ResolveWebhookEventActionTest.php index 44e48dd..74ec069 100644 --- a/tests/Action/Api/ResolveWebhookEventActionTest.php +++ b/tests/Action/Api/ResolveWebhookEventActionTest.php @@ -43,7 +43,7 @@ public function testShouldThrowLogicExceptionWhenNoStripeSignatureIsFound(): voi ->method('execute') ->with($this->isInstanceOf(GetHttpRequest::class)); - $apiMock = $this->createApiMock(false); + $apiMock = $this->createApiMock(); $action->setApiClass(KeysAwareInterface::class); $action->setGateway($gatewayMock); @@ -81,7 +81,7 @@ public function testShouldThrowExceptionWhenSignatureFailed(): void $this->throwException(SignatureVerificationException::factory('')) ); - $apiMock = $this->createApiMock(false); + $apiMock = $this->createApiMock(); $apiMock ->expects($this->once()) ->method('getWebhookSecretKeys') @@ -131,7 +131,7 @@ public function testShouldResolveWebhookEventWithSymfonyRequestBridge(): void }) ); - $apiMock = $this->createApiMock(false); + $apiMock = $this->createApiMock(); $apiMock ->expects($this->once()) ->method('getWebhookSecretKeys') @@ -182,7 +182,7 @@ public function testShouldResolveWebhookEventWithPlainPHP(): void }) ); - $apiMock = $this->createApiMock(false); + $apiMock = $this->createApiMock(); $apiMock ->expects($this->once()) ->method('getWebhookSecretKeys') @@ -230,7 +230,7 @@ public function testShouldRequestNotSupportedExceptionWhenTheWebhookCanNotBeReso }) ); - $apiMock = $this->createApiMock(false); + $apiMock = $this->createApiMock(); $apiMock ->expects($this->once()) ->method('getWebhookSecretKeys') diff --git a/tests/Action/Api/Resource/AllActionTest.php b/tests/Action/Api/Resource/AllActionTest.php index 4fcde0c..19f3140 100644 --- a/tests/Action/Api/Resource/AllActionTest.php +++ b/tests/Action/Api/Resource/AllActionTest.php @@ -8,6 +8,9 @@ use FluxSE\PayumStripe\Action\Api\Resource\AllCouponAction; use FluxSE\PayumStripe\Action\Api\Resource\AllCustomerAction; use FluxSE\PayumStripe\Action\Api\Resource\AllInvoiceAction; +use FluxSE\PayumStripe\Action\Api\Resource\AllPlanAction; +use FluxSE\PayumStripe\Action\Api\Resource\AllPriceAction; +use FluxSE\PayumStripe\Action\Api\Resource\AllProductAction; use FluxSE\PayumStripe\Action\Api\Resource\AllResourceActionInterface; use FluxSE\PayumStripe\Action\Api\Resource\AllSessionAction; use FluxSE\PayumStripe\Action\Api\Resource\AllTaxRateAction; @@ -17,6 +20,9 @@ use FluxSE\PayumStripe\Request\Api\Resource\AllCustomer; use FluxSE\PayumStripe\Request\Api\Resource\AllInterface; use FluxSE\PayumStripe\Request\Api\Resource\AllInvoice; +use FluxSE\PayumStripe\Request\Api\Resource\AllPlan; +use FluxSE\PayumStripe\Request\Api\Resource\AllPrice; +use FluxSE\PayumStripe\Request\Api\Resource\AllProduct; use FluxSE\PayumStripe\Request\Api\Resource\AllSession; use FluxSE\PayumStripe\Request\Api\Resource\AllTaxRate; use LogicException; @@ -29,7 +35,19 @@ use Stripe\Coupon; use Stripe\Customer; use Stripe\Invoice; -use Stripe\Issuing\CardDetails; +use Stripe\Plan; +use Stripe\Price; +use Stripe\Product; +use Stripe\Service\AbstractService; +use Stripe\Service\Checkout\SessionService; +use Stripe\Service\CouponService; +use Stripe\Service\CustomerService; +use Stripe\Service\InvoiceService; +use Stripe\Service\PlanService; +use Stripe\Service\PriceService; +use Stripe\Service\ProductService; +use Stripe\Service\TaxRateService; +use Stripe\StripeClient; use Stripe\TaxRate; use Tests\FluxSE\PayumStripe\Action\Api\ApiAwareActionTestTrait; use Tests\FluxSE\PayumStripe\Stripe\StripeApiTestHelper; @@ -60,15 +78,16 @@ public function testShouldImplements(string $allActionClass): void public function testShouldAllAPaymentIntent( string $allActionClass, string $allRequestClass, - string $allClass + string $allClass, + string $serviceClass ): void { $apiMock = $this->createApiMock(); + $stripeClient = $apiMock->getStripeClient(); /** @var AbstractAllAction $action */ $action = new $allActionClass(); $action->setApiClass(KeysAwareInterface::class); $action->setApi($apiMock); - $this->assertEquals($allClass, $action->getApiResourceClass()); /** @var AbstractAll $request */ $request = new $allRequestClass(); @@ -106,6 +125,9 @@ public function testShouldAllAPaymentIntent( $action->execute($request); $this->assertContainsOnlyInstancesOf($allClass, $request->getApiResources()); + + $service = $action->getStripeService($stripeClient); + $this->assertInstanceOf($serviceClass, $service); } public function testShouldThrowExceptionIfApiResourceClassIsNotCreatable(): void @@ -115,10 +137,13 @@ public function supportAlso(AllInterface $request): bool { return true; } - }; - $action->setApiResourceClass(CardDetails::class); - $this->assertEquals(CardDetails::class, $action->getApiResourceClass()); + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return new class($stripeClient) extends AbstractService { + }; + } + }; $request = new class() extends AbstractAll { }; @@ -136,11 +161,14 @@ public function supportAlso(AllInterface $request): bool public function requestList(): array { return [ - [AllCouponAction::class, AllCoupon::class, Coupon::class], - [AllCustomerAction::class, AllCustomer::class, Customer::class], - [AllInvoiceAction::class, AllInvoice::class, Invoice::class], - [AllTaxRateAction::class, AllTaxRate::class, TaxRate::class], - [AllSessionAction::class, AllSession::class, Session::class], + [AllCouponAction::class, AllCoupon::class, Coupon::class, CouponService::class], + [AllCustomerAction::class, AllCustomer::class, Customer::class, CustomerService::class], + [AllInvoiceAction::class, AllInvoice::class, Invoice::class, InvoiceService::class], + [AllPlanAction::class, AllPlan::class, Plan::class, PlanService::class], + [AllPriceAction::class, AllPrice::class, Price::class, PriceService::class], + [AllProductAction::class, AllProduct::class, Product::class, ProductService::class], + [AllTaxRateAction::class, AllTaxRate::class, TaxRate::class, TaxRateService::class], + [AllSessionAction::class, AllSession::class, Session::class, SessionService::class], ]; } } diff --git a/tests/Action/Api/Resource/CreateActionTest.php b/tests/Action/Api/Resource/CreateActionTest.php index 2fba757..dbcd9bb 100644 --- a/tests/Action/Api/Resource/CreateActionTest.php +++ b/tests/Action/Api/Resource/CreateActionTest.php @@ -8,6 +8,8 @@ use FluxSE\PayumStripe\Action\Api\Resource\CreatePaymentIntentAction; use FluxSE\PayumStripe\Action\Api\Resource\CreatePaymentMethodAction; use FluxSE\PayumStripe\Action\Api\Resource\CreatePlanAction; +use FluxSE\PayumStripe\Action\Api\Resource\CreatePriceAction; +use FluxSE\PayumStripe\Action\Api\Resource\CreateProductAction; use FluxSE\PayumStripe\Action\Api\Resource\CreateRefundAction; use FluxSE\PayumStripe\Action\Api\Resource\CreateResourceActionInterface; use FluxSE\PayumStripe\Action\Api\Resource\CreateSessionAction; @@ -22,6 +24,8 @@ use FluxSE\PayumStripe\Request\Api\Resource\CreatePaymentIntent; use FluxSE\PayumStripe\Request\Api\Resource\CreatePaymentMethod; use FluxSE\PayumStripe\Request\Api\Resource\CreatePlan; +use FluxSE\PayumStripe\Request\Api\Resource\CreatePrice; +use FluxSE\PayumStripe\Request\Api\Resource\CreateProduct; use FluxSE\PayumStripe\Request\Api\Resource\CreateRefund; use FluxSE\PayumStripe\Request\Api\Resource\CreateSession; use FluxSE\PayumStripe\Request\Api\Resource\CreateSetupIntent; @@ -40,8 +44,24 @@ use Stripe\PaymentIntent; use Stripe\PaymentMethod; use Stripe\Plan; +use Stripe\Price; +use Stripe\Product; use Stripe\Refund; +use Stripe\Service\AbstractService; +use Stripe\Service\Checkout\SessionService; +use Stripe\Service\CouponService; +use Stripe\Service\CustomerService; +use Stripe\Service\PaymentIntentService; +use Stripe\Service\PaymentMethodService; +use Stripe\Service\PlanService; +use Stripe\Service\PriceService; +use Stripe\Service\ProductService; +use Stripe\Service\RefundService; +use Stripe\Service\SetupIntentService; +use Stripe\Service\SubscriptionService; +use Stripe\Service\TaxRateService; use Stripe\SetupIntent; +use Stripe\StripeClient; use Stripe\Subscription; use Stripe\TaxRate; use Tests\FluxSE\PayumStripe\Action\Api\ApiAwareActionTestTrait; @@ -73,16 +93,17 @@ public function testShouldImplements(string $createActionClass): void public function testShouldCreateAnApiRessource( string $createActionClass, string $createRequestClass, - string $createClass + string $createClass, + string $serviceClass ): void { $model = []; $apiMock = $this->createApiMock(); + $stripeClient = $apiMock->getStripeClient(); /** @var AbstractCreateAction $action */ $action = new $createActionClass(); $action->setApiClass(KeysAwareInterface::class); - $this->assertEquals($createClass, $action->getApiResourceClass()); $action->setApi($apiMock); /** @var AbstractCreate $request */ @@ -109,6 +130,9 @@ public function testShouldCreateAnApiRessource( $action->execute($request); $this->assertInstanceOf($createClass, $request->getApiResource()); + + $service = $action->getStripeService($stripeClient); + $this->assertInstanceOf($serviceClass, $service); } public function testShouldThrowExceptionIfApiResourceClassIsNotCreatable(): void @@ -119,10 +143,13 @@ public function supportAlso(CreateInterface $request): bool { return true; } - }; - $action->setApiResourceClass(CardDetails::class); - $this->assertEquals(CardDetails::class, $action->getApiResourceClass()); + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return new class() extends AbstractService { + }; + } + }; $request = new class($model) extends AbstractCreate { }; @@ -135,16 +162,18 @@ public function supportAlso(CreateInterface $request): bool public function requestList(): array { return [ - [CreateCouponAction::class, CreateCoupon::class, Coupon::class], - [CreateCustomerAction::class, CreateCustomer::class, Customer::class], - [CreateSessionAction::class, CreateSession::class, Session::class], - [CreatePaymentIntentAction::class, CreatePaymentIntent::class, PaymentIntent::class], - [CreatePaymentMethodAction::class, CreatePaymentMethod::class, PaymentMethod::class], - [CreatePlanAction::class, CreatePlan::class, Plan::class], - [CreateRefundAction::class, CreateRefund::class, Refund::class], - [CreateSetupIntentAction::class, CreateSetupIntent::class, SetupIntent::class], - [CreateSubscriptionAction::class, CreateSubscription::class, Subscription::class], - [CreateTaxRateAction::class, CreateTaxRate::class, TaxRate::class], + [CreateCouponAction::class, CreateCoupon::class, Coupon::class, CouponService::class], + [CreateCustomerAction::class, CreateCustomer::class, Customer::class, CustomerService::class], + [CreateSessionAction::class, CreateSession::class, Session::class, SessionService::class], + [CreatePaymentIntentAction::class, CreatePaymentIntent::class, PaymentIntent::class, PaymentIntentService::class], + [CreatePaymentMethodAction::class, CreatePaymentMethod::class, PaymentMethod::class, PaymentMethodService::class], + [CreatePlanAction::class, CreatePlan::class, Plan::class, PlanService::class], + [CreatePriceAction::class, CreatePrice::class, Price::class, PriceService::class], + [CreateProductAction::class, CreateProduct::class, Product::class, ProductService::class], + [CreateRefundAction::class, CreateRefund::class, Refund::class, RefundService::class], + [CreateSetupIntentAction::class, CreateSetupIntent::class, SetupIntent::class, SetupIntentService::class], + [CreateSubscriptionAction::class, CreateSubscription::class, Subscription::class, SubscriptionService::class], + [CreateTaxRateAction::class, CreateTaxRate::class, TaxRate::class, TaxRateService::class], ]; } } diff --git a/tests/Action/Api/Resource/CustomCallActionTest.php b/tests/Action/Api/Resource/CustomCallActionTest.php index 6774f28..d45b901 100644 --- a/tests/Action/Api/Resource/CustomCallActionTest.php +++ b/tests/Action/Api/Resource/CustomCallActionTest.php @@ -71,7 +71,6 @@ public function testShouldCallCustom( $action = new $customCallActionClass(); $action->setApiClass(KeysAwareInterface::class); $action->setApi($apiMock); - $this->assertEquals($customCallClass, $action->getApiResourceClass()); /** @var AbstractCustomCall $request */ $request = new $customCallRequestClass($id); diff --git a/tests/Action/Api/Resource/DeleteActionTest.php b/tests/Action/Api/Resource/DeleteActionTest.php index 121d08b..0eb55c6 100644 --- a/tests/Action/Api/Resource/DeleteActionTest.php +++ b/tests/Action/Api/Resource/DeleteActionTest.php @@ -5,12 +5,14 @@ use FluxSE\PayumStripe\Action\Api\Resource\AbstractDeleteAction; use FluxSE\PayumStripe\Action\Api\Resource\DeleteCouponAction; use FluxSE\PayumStripe\Action\Api\Resource\DeletePlanAction; +use FluxSE\PayumStripe\Action\Api\Resource\DeleteProductAction; use FluxSE\PayumStripe\Action\Api\Resource\DeleteResourceActionInterface; use FluxSE\PayumStripe\Api\KeysAwareInterface; use FluxSE\PayumStripe\Request\Api\Resource\AbstractDelete; use FluxSE\PayumStripe\Request\Api\Resource\DeleteCoupon; use FluxSE\PayumStripe\Request\Api\Resource\DeleteInterface; use FluxSE\PayumStripe\Request\Api\Resource\DeletePlan; +use FluxSE\PayumStripe\Request\Api\Resource\DeleteProduct; use LogicException; use Payum\Core\Action\ActionInterface; use Payum\Core\ApiAwareInterface; @@ -22,7 +24,13 @@ use Stripe\Issuing\Card; use Stripe\Issuing\CardDetails; use Stripe\Plan; +use Stripe\Product; +use Stripe\Service\AbstractService; +use Stripe\Service\CouponService; +use Stripe\Service\PlanService; +use Stripe\Service\ProductService; use Stripe\Stripe; +use Stripe\StripeClient; use Tests\FluxSE\PayumStripe\Action\Api\ApiAwareActionTestTrait; use Tests\FluxSE\PayumStripe\Stripe\StripeApiTestHelper; @@ -52,17 +60,18 @@ public function testShouldImplements(string $deleteActionClass): void public function testShouldBeDeleted( string $deleteActionClass, string $deleteRequestClass, - string $deleteClass + string $deleteClass, + string $serviceClass ): void { $id = 'pi_1'; $apiMock = $this->createApiMock(); + $stripeClient = $apiMock->getStripeClient(); /** @var AbstractDeleteAction $action */ $action = new $deleteActionClass(); $action->setApiClass(KeysAwareInterface::class); $action->setApi($apiMock); - $this->assertEquals($deleteClass, $action->getApiResourceClass()); /** @var AbstractDelete $request */ $request = new $deleteRequestClass($id); @@ -111,6 +120,9 @@ public function testShouldBeDeleted( $action->execute($request); $this->assertInstanceOf($deleteClass, $request->getApiResource()); + + $service = $action->getStripeService($stripeClient); + $this->assertInstanceOf($serviceClass, $service); } /** @@ -124,10 +136,13 @@ public function supportAlso(DeleteInterface $request): bool { return true; } - }; - $action->setApiResourceClass($faultClass); - $this->assertEquals($faultClass, $action->getApiResourceClass()); + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return new class() extends AbstractService { + }; + } + }; $request = new class($id) extends AbstractDelete { }; @@ -148,8 +163,9 @@ public function faultList(): array public function requestList(): array { return [ - [DeleteCouponAction::class, DeleteCoupon::class, Coupon::class], - [DeletePlanAction::class, DeletePlan::class, Plan::class], + [DeleteCouponAction::class, DeleteCoupon::class, Coupon::class, CouponService::class], + [DeletePlanAction::class, DeletePlan::class, Plan::class, PlanService::class], + [DeleteProductAction::class, DeleteProduct::class, Product::class, ProductService::class], ]; } } diff --git a/tests/Action/Api/Resource/RetrieveActionTest.php b/tests/Action/Api/Resource/RetrieveActionTest.php index 9562d73..addf5ee 100644 --- a/tests/Action/Api/Resource/RetrieveActionTest.php +++ b/tests/Action/Api/Resource/RetrieveActionTest.php @@ -10,6 +10,7 @@ use FluxSE\PayumStripe\Action\Api\Resource\RetrievePaymentIntentAction; use FluxSE\PayumStripe\Action\Api\Resource\RetrievePaymentMethodAction; use FluxSE\PayumStripe\Action\Api\Resource\RetrievePlanAction; +use FluxSE\PayumStripe\Action\Api\Resource\RetrievePriceAction; use FluxSE\PayumStripe\Action\Api\Resource\RetrieveProductAction; use FluxSE\PayumStripe\Action\Api\Resource\RetrieveResourceActionInterface; use FluxSE\PayumStripe\Action\Api\Resource\RetrieveSessionAction; @@ -25,6 +26,7 @@ use FluxSE\PayumStripe\Request\Api\Resource\RetrievePaymentIntent; use FluxSE\PayumStripe\Request\Api\Resource\RetrievePaymentMethod; use FluxSE\PayumStripe\Request\Api\Resource\RetrievePlan; +use FluxSE\PayumStripe\Request\Api\Resource\RetrievePrice; use FluxSE\PayumStripe\Request\Api\Resource\RetrieveProduct; use FluxSE\PayumStripe\Request\Api\Resource\RetrieveSession; use FluxSE\PayumStripe\Request\Api\Resource\RetrieveSetupIntent; @@ -44,8 +46,23 @@ use Stripe\PaymentIntent; use Stripe\PaymentMethod; use Stripe\Plan; +use Stripe\Price; use Stripe\Product; +use Stripe\Service\AbstractService; +use Stripe\Service\ChargeService; +use Stripe\Service\Checkout\SessionService; +use Stripe\Service\CouponService; +use Stripe\Service\CustomerService; +use Stripe\Service\InvoiceService; +use Stripe\Service\PaymentIntentService; +use Stripe\Service\PaymentMethodService; +use Stripe\Service\PlanService; +use Stripe\Service\PriceService; +use Stripe\Service\ProductService; +use Stripe\Service\SetupIntentService; +use Stripe\Service\SubscriptionService; use Stripe\SetupIntent; +use Stripe\StripeClient; use Stripe\Subscription; use Tests\FluxSE\PayumStripe\Action\Api\ApiAwareActionTestTrait; use Tests\FluxSE\PayumStripe\Stripe\StripeApiTestHelper; @@ -76,17 +93,18 @@ public function testShouldImplements(string $retrieveActionClass): void public function testShouldBeRetrieved( string $retrieveActionClass, string $retrieveRequestClass, - string $retrieveClass + string $retrieveClass, + string $serviceClass ): void { $id = 'pi_1'; $apiMock = $this->createApiMock(); + $stripeClient = $apiMock->getStripeClient(); /** @var AbstractRetrieveAction $action */ $action = new $retrieveActionClass(); $action->setApiClass(KeysAwareInterface::class); $action->setApi($apiMock); - $this->assertEquals($retrieveClass, $action->getApiResourceClass()); /** @var AbstractRetrieve $request */ $request = new $retrieveRequestClass($id); @@ -112,6 +130,9 @@ public function testShouldBeRetrieved( $action->execute($request); $this->assertInstanceOf($retrieveClass, $request->getApiResource()); + + $service = $action->getStripeService($stripeClient); + $this->assertInstanceOf($serviceClass, $service); } public function testShouldThrowExceptionIfApiResourceClassIsNotCreatable(): void @@ -122,10 +143,13 @@ public function supportAlso(RetrieveInterface $request): bool { return true; } - }; - $action->setApiResourceClass(CardDetails::class); - $this->assertEquals(CardDetails::class, $action->getApiResourceClass()); + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return new class() extends AbstractService { + }; + } + }; $request = new class($id) extends AbstractRetrieve { }; @@ -143,17 +167,18 @@ public function supportAlso(RetrieveInterface $request): bool public function requestList(): array { return [ - [RetrieveChargeAction::class, RetrieveCharge::class, Charge::class], - [RetrieveCouponAction::class, RetrieveCoupon::class, Coupon::class], - [RetrieveCustomerAction::class, RetrieveCustomer::class, Customer::class], - [RetrieveInvoiceAction::class, RetrieveInvoice::class, Invoice::class], - [RetrievePaymentIntentAction::class, RetrievePaymentIntent::class, PaymentIntent::class], - [RetrievePaymentMethodAction::class, RetrievePaymentMethod::class, PaymentMethod::class], - [RetrievePlanAction::class, RetrievePlan::class, Plan::class], - [RetrieveProductAction::class, RetrieveProduct::class, Product::class], - [RetrieveSessionAction::class, RetrieveSession::class, Session::class], - [RetrieveSetupIntentAction::class, RetrieveSetupIntent::class, SetupIntent::class], - [RetrieveSubscriptionAction::class, RetrieveSubscription::class, Subscription::class], + [RetrieveChargeAction::class, RetrieveCharge::class, Charge::class, ChargeService::class], + [RetrieveCouponAction::class, RetrieveCoupon::class, Coupon::class, CouponService::class], + [RetrieveCustomerAction::class, RetrieveCustomer::class, Customer::class, CustomerService::class], + [RetrieveInvoiceAction::class, RetrieveInvoice::class, Invoice::class, InvoiceService::class], + [RetrievePaymentIntentAction::class, RetrievePaymentIntent::class, PaymentIntent::class, PaymentIntentService::class], + [RetrievePaymentMethodAction::class, RetrievePaymentMethod::class, PaymentMethod::class, PaymentMethodService::class], + [RetrievePlanAction::class, RetrievePlan::class, Plan::class, PlanService::class], + [RetrievePriceAction::class, RetrievePrice::class, Price::class, PriceService::class], + [RetrieveProductAction::class, RetrieveProduct::class, Product::class, ProductService::class], + [RetrieveSessionAction::class, RetrieveSession::class, Session::class, SessionService::class], + [RetrieveSetupIntentAction::class, RetrieveSetupIntent::class, SetupIntent::class, SetupIntentService::class], + [RetrieveSubscriptionAction::class, RetrieveSubscription::class, Subscription::class, SubscriptionService::class], ]; } } diff --git a/tests/Action/Api/Resource/UpdateActionTest.php b/tests/Action/Api/Resource/UpdateActionTest.php index 9b804c8..3a00b91 100644 --- a/tests/Action/Api/Resource/UpdateActionTest.php +++ b/tests/Action/Api/Resource/UpdateActionTest.php @@ -5,6 +5,9 @@ use FluxSE\PayumStripe\Action\Api\Resource\AbstractUpdateAction; use FluxSE\PayumStripe\Action\Api\Resource\UpdateCouponAction; use FluxSE\PayumStripe\Action\Api\Resource\UpdatePaymentIntentAction; +use FluxSE\PayumStripe\Action\Api\Resource\UpdatePlanAction; +use FluxSE\PayumStripe\Action\Api\Resource\UpdatePriceAction; +use FluxSE\PayumStripe\Action\Api\Resource\UpdateProductAction; use FluxSE\PayumStripe\Action\Api\Resource\UpdateResourceActionInterface; use FluxSE\PayumStripe\Action\Api\Resource\UpdateSubscriptionAction; use FluxSE\PayumStripe\Api\KeysAwareInterface; @@ -12,6 +15,9 @@ use FluxSE\PayumStripe\Request\Api\Resource\UpdateCoupon; use FluxSE\PayumStripe\Request\Api\Resource\UpdateInterface; use FluxSE\PayumStripe\Request\Api\Resource\UpdatePaymentIntent; +use FluxSE\PayumStripe\Request\Api\Resource\UpdatePlan; +use FluxSE\PayumStripe\Request\Api\Resource\UpdatePrice; +use FluxSE\PayumStripe\Request\Api\Resource\UpdateProduct; use FluxSE\PayumStripe\Request\Api\Resource\UpdateSubscription; use LogicException; use Payum\Core\Action\ActionInterface; @@ -22,6 +28,17 @@ use Stripe\Coupon; use Stripe\Issuing\CardDetails; use Stripe\PaymentIntent; +use Stripe\Plan; +use Stripe\Price; +use Stripe\Product; +use Stripe\Service\AbstractService; +use Stripe\Service\CouponService; +use Stripe\Service\PaymentIntentService; +use Stripe\Service\PlanService; +use Stripe\Service\PriceService; +use Stripe\Service\ProductService; +use Stripe\Service\SubscriptionService; +use Stripe\StripeClient; use Stripe\Subscription; use Tests\FluxSE\PayumStripe\Action\Api\ApiAwareActionTestTrait; use Tests\FluxSE\PayumStripe\Stripe\StripeApiTestHelper; @@ -52,18 +69,19 @@ public function testShouldImplements(string $updateActionClass): void public function testShouldUpdateAPaymentIntent( string $updateActionClass, string $updateRequestClass, - string $updateClass + string $updateClass, + string $serviceClass ): void { $id = 'pi_1'; $parameters = []; $apiMock = $this->createApiMock(); + $stripeClient = $apiMock->getStripeClient(); /** @var AbstractUpdateAction $action */ $action = new $updateActionClass(); $action->setApiClass(KeysAwareInterface::class); $action->setApi($apiMock); - $this->assertEquals($updateClass, $action->getApiResourceClass()); /** @var AbstractUpdate $request */ $request = new $updateRequestClass($id, $parameters); @@ -89,6 +107,9 @@ public function testShouldUpdateAPaymentIntent( $action->execute($request); $this->assertInstanceOf($updateClass, $request->getApiResource()); + + $service = $action->getStripeService($stripeClient); + $this->assertInstanceOf($serviceClass, $service); } public function testShouldThrowExceptionIfApiResourceClassIsNotCreatable(): void @@ -100,10 +121,13 @@ public function supportAlso(UpdateInterface $request): bool { return true; } - }; - $action->setApiResourceClass(CardDetails::class); - $this->assertEquals(CardDetails::class, $action->getApiResourceClass()); + public function getStripeService(StripeClient $stripeClient): AbstractService + { + return new class() extends AbstractService { + }; + } + }; $request = new class($id, $parameters) extends AbstractUpdate { }; @@ -121,9 +145,12 @@ public function supportAlso(UpdateInterface $request): bool public function requestList(): array { return [ - [UpdateCouponAction::class, UpdateCoupon::class, Coupon::class], - [UpdatePaymentIntentAction::class, UpdatePaymentIntent::class, PaymentIntent::class], - [UpdateSubscriptionAction::class, UpdateSubscription::class, Subscription::class], + [UpdateCouponAction::class, UpdateCoupon::class, Coupon::class, CouponService::class], + [UpdatePaymentIntentAction::class, UpdatePaymentIntent::class, PaymentIntent::class, PaymentIntentService::class], + [UpdatePlanAction::class, UpdatePlan::class, Plan::class, PlanService::class], + [UpdatePriceAction::class, UpdatePrice::class, Price::class, PriceService::class], + [UpdateProductAction::class, UpdateProduct::class, Product::class, ProductService::class], + [UpdateSubscriptionAction::class, UpdateSubscription::class, Subscription::class, SubscriptionService::class], ]; } } diff --git a/tests/Action/Api/StripeApiAwareTraitTest.php b/tests/Action/Api/StripeApiAwareTraitTest.php index d665f93..f079753 100644 --- a/tests/Action/Api/StripeApiAwareTraitTest.php +++ b/tests/Action/Api/StripeApiAwareTraitTest.php @@ -5,8 +5,8 @@ namespace Tests\FluxSE\PayumStripe\Action\Api; use FluxSE\PayumStripe\Action\Api\StripeApiAwareTrait; -use FluxSE\PayumStripe\Api\KeysAwareInterface; -use FluxSE\PayumStripe\Api\KeysAwareTrait; +use FluxSE\PayumStripe\Api\StripeClientAwareInterface; +use FluxSE\PayumStripe\Api\StripeClientAwareTrait; use PHPUnit\Framework\TestCase; final class StripeApiAwareTraitTest extends TestCase @@ -14,13 +14,13 @@ final class StripeApiAwareTraitTest extends TestCase public function testShouldGetApiClass(): void { $trait = $this->getObjectForTrait(StripeApiAwareTrait::class); - $this->assertEquals(KeysAwareInterface::class, $trait->getApiClass()); + $this->assertEquals(StripeClientAwareInterface::class, $trait->getApiClass()); } public function testShouldSetApiClass(): void { $trait = $this->getObjectForTrait(StripeApiAwareTrait::class); - $trait->setApiClass(KeysAwareTrait::class); - $this->assertEquals(KeysAwareTrait::class, $trait->getApiClass()); + $trait->setApiClass(StripeClientAwareTrait::class); + $this->assertEquals(StripeClientAwareTrait::class, $trait->getApiClass()); } } diff --git a/tests/Action/StripeCheckoutSession/ConvertPaymentActionTest.php b/tests/Action/StripeCheckoutSession/ConvertPaymentActionTest.php index f05ef7a..6be5825 100644 --- a/tests/Action/StripeCheckoutSession/ConvertPaymentActionTest.php +++ b/tests/Action/StripeCheckoutSession/ConvertPaymentActionTest.php @@ -48,7 +48,7 @@ public function testShouldCorrectlyConvertPaymentToDetailsAndSetItBack(): void $action = new ConvertPaymentAction(); - $apiMock = $this->createApiMock(false); + $apiMock = $this->createApiMock(); $apiMock ->expects($this->once()) ->method('getPaymentMethodTypes') @@ -105,7 +105,7 @@ public function testShouldNotOverwriteAlreadySetExtraDetails(): void $action = new ConvertPaymentAction(); - $apiMock = $this->createApiMock(false); + $apiMock = $this->createApiMock(); $apiMock ->expects($this->once()) ->method('getPaymentMethodTypes') @@ -143,7 +143,7 @@ public function testShouldNotOverwriteAlreadySetPaymentMethodTypes(): void $action = new ConvertPaymentAction(); - $apiMock = $this->createApiMock(false); + $apiMock = $this->createApiMock(); $apiMock ->expects($this->once()) ->method('getPaymentMethodTypes') @@ -181,7 +181,7 @@ public function testShouldNotOverwriteAlreadySetCustomerEmail(): void $action = new ConvertPaymentAction(); - $apiMock = $this->createApiMock(false); + $apiMock = $this->createApiMock(); $apiMock ->expects($this->once()) ->method('getPaymentMethodTypes') @@ -219,7 +219,7 @@ public function testShouldNotOverwriteAlreadySetLineItems(): void $action = new ConvertPaymentAction(); - $apiMock = $this->createApiMock(false); + $apiMock = $this->createApiMock(); $apiMock ->expects($this->once()) ->method('getPaymentMethodTypes') @@ -254,7 +254,7 @@ public function testPaymentMethodTypes(): void $action = new ConvertPaymentAction(); - $apiMock = $this->createApiMock(false); + $apiMock = $this->createApiMock(); $apiMock ->expects($this->once()) ->method('getPaymentMethodTypes') diff --git a/tests/Action/StripeJs/Api/RenderStripeJsActionTest.php b/tests/Action/StripeJs/Api/RenderStripeJsActionTest.php index 0c918c4..b95bdbc 100644 --- a/tests/Action/StripeJs/Api/RenderStripeJsActionTest.php +++ b/tests/Action/StripeJs/Api/RenderStripeJsActionTest.php @@ -83,7 +83,7 @@ public function testShouldNotSupportObtainTokenRequestWithNotArrayAccessModel(st $request->setResult(''); }); - $apiMock = $this->createApiMock(false); + $apiMock = $this->createApiMock(); $apiMock ->expects($this->once()) ->method('getPublishableKey') diff --git a/tests/Api/KeysAwareApiTest.php b/tests/Api/KeysAwareApiTrait.php similarity index 76% rename from tests/Api/KeysAwareApiTest.php rename to tests/Api/KeysAwareApiTrait.php index 985ae07..5280817 100644 --- a/tests/Api/KeysAwareApiTest.php +++ b/tests/Api/KeysAwareApiTrait.php @@ -4,25 +4,8 @@ namespace Tests\FluxSE\PayumStripe\Api; -use FluxSE\PayumStripe\Api\KeysAwareInterface; -use ReflectionClass; - -trait KeysAwareApiTest +trait KeysAwareApiTrait { - abstract protected function getApiClass(): string; - - protected function getReflectionApiClass(): ReflectionClass - { - return new ReflectionClass($this->getApiClass()); - } - - public function test__construct(): void - { - $api = $this->getReflectionApiClass()->newInstance('', ''); - - $this->assertInstanceOf(KeysAwareInterface::class, $api); - } - public function testHasWebhookSecretKey(): void { $api = $this->getReflectionApiClass()->newInstance('', '', ['webhookKey1']); diff --git a/tests/Api/StripeCheckoutSessionApiTest.php b/tests/Api/StripeCheckoutSessionApiTest.php index 32bf704..78ee7f9 100644 --- a/tests/Api/StripeCheckoutSessionApiTest.php +++ b/tests/Api/StripeCheckoutSessionApiTest.php @@ -9,7 +9,7 @@ final class StripeCheckoutSessionApiTest extends TestCase { - use KeysAwareApiTest; + use StripeClientAwareApiTrait; protected function getApiClass(): string { diff --git a/tests/Api/StripeClientAwareApiTrait.php b/tests/Api/StripeClientAwareApiTrait.php new file mode 100644 index 0000000..584070e --- /dev/null +++ b/tests/Api/StripeClientAwareApiTrait.php @@ -0,0 +1,51 @@ +getApiClass()); + } + + public function test__construct(): void + { + $api = $this->getReflectionApiClass()->newInstance('', ''); + + $this->assertInstanceOf(StripeClientAwareInterface::class, $api); + } + + public function testGetClientId(): void + { + $api = $this->getReflectionApiClass()->newInstance('', '', [], '12345'); + $this->assertEquals('12345', $api->getClientId()); + } + + public function testGetStripeAccount(): void + { + $api = $this->getReflectionApiClass()->newInstance('', '', [], null, '12345'); + $this->assertEquals('12345', $api->getStripeAccount()); + } + + public function testGetStripeVersion(): void + { + $api = $this->getReflectionApiClass()->newInstance('', '', [], null, null, '1'); + $this->assertEquals('1', $api->getStripeVersion()); + } + + public function testGetStripeClient(): void + { + $api = $this->getReflectionApiClass()->newInstance('', '12345'); + $this->assertInstanceOf(StripeClient::class, $api->getStripeClient()); + } +} diff --git a/tests/Api/StripeJsApiTest.php b/tests/Api/StripeJsApiTest.php index 589b39f..0a7cfd9 100644 --- a/tests/Api/StripeJsApiTest.php +++ b/tests/Api/StripeJsApiTest.php @@ -8,7 +8,7 @@ final class StripeJsApiTest extends TestCase { - use KeysAwareApiTest; + use StripeClientAwareApiTrait; protected function getApiClass(): string { diff --git a/tests/Request/Api/Resource/AllTest.php b/tests/Request/Api/Resource/AllTest.php index c1fe0ef..9e3dff4 100644 --- a/tests/Request/Api/Resource/AllTest.php +++ b/tests/Request/Api/Resource/AllTest.php @@ -9,6 +9,9 @@ use FluxSE\PayumStripe\Request\Api\Resource\AllCustomer; use FluxSE\PayumStripe\Request\Api\Resource\AllInterface; use FluxSE\PayumStripe\Request\Api\Resource\AllInvoice; +use FluxSE\PayumStripe\Request\Api\Resource\AllPlan; +use FluxSE\PayumStripe\Request\Api\Resource\AllPrice; +use FluxSE\PayumStripe\Request\Api\Resource\AllProduct; use FluxSE\PayumStripe\Request\Api\Resource\AllSession; use FluxSE\PayumStripe\Request\Api\Resource\AllTaxRate; use FluxSE\PayumStripe\Request\Api\Resource\OptionsAwareInterface; @@ -20,6 +23,9 @@ use Stripe\Coupon; use Stripe\Customer; use Stripe\Invoice; +use Stripe\Plan; +use Stripe\Price; +use Stripe\Product; use Stripe\TaxRate; final class AllTest extends TestCase @@ -107,6 +113,9 @@ public function requestList(): array [AllCoupon::class, Coupon::class], [AllCustomer::class, Customer::class], [AllInvoice::class, Invoice::class], + [AllPlan::class, Plan::class], + [AllPrice::class, Price::class], + [AllProduct::class, Product::class], [AllTaxRate::class, TaxRate::class], [AllSession::class, Session::class], ]; diff --git a/tests/Request/Api/Resource/CreateTest.php b/tests/Request/Api/Resource/CreateTest.php index eef6b43..f05502c 100644 --- a/tests/Request/Api/Resource/CreateTest.php +++ b/tests/Request/Api/Resource/CreateTest.php @@ -8,6 +8,8 @@ use FluxSE\PayumStripe\Request\Api\Resource\CreatePaymentIntent; use FluxSE\PayumStripe\Request\Api\Resource\CreatePaymentMethod; use FluxSE\PayumStripe\Request\Api\Resource\CreatePlan; +use FluxSE\PayumStripe\Request\Api\Resource\CreatePrice; +use FluxSE\PayumStripe\Request\Api\Resource\CreateProduct; use FluxSE\PayumStripe\Request\Api\Resource\CreateRefund; use FluxSE\PayumStripe\Request\Api\Resource\CreateSession; use FluxSE\PayumStripe\Request\Api\Resource\CreateSubscription; @@ -24,6 +26,8 @@ use Stripe\PaymentIntent; use Stripe\PaymentMethod; use Stripe\Plan; +use Stripe\Price; +use Stripe\Product; use Stripe\Refund; use Stripe\Subscription; use Stripe\TaxRate; @@ -126,6 +130,8 @@ public function requestList(): array [CreatePaymentIntent::class, PaymentIntent::class], [CreatePaymentMethod::class, PaymentMethod::class], [CreatePlan::class, Plan::class], + [CreatePrice::class, Price::class], + [CreateProduct::class, Product::class], [CreateRefund::class, Refund::class], [CreateSubscription::class, Subscription::class], [CreateTaxRate::class, TaxRate::class], diff --git a/tests/Request/Api/Resource/DeleteTest.php b/tests/Request/Api/Resource/DeleteTest.php index c7735af..5d7a173 100644 --- a/tests/Request/Api/Resource/DeleteTest.php +++ b/tests/Request/Api/Resource/DeleteTest.php @@ -5,8 +5,10 @@ namespace Tests\FluxSE\PayumStripe\Request\Api\Resource; use FluxSE\PayumStripe\Request\Api\Resource\AbstractDelete; +use FluxSE\PayumStripe\Request\Api\Resource\DeleteCoupon; use FluxSE\PayumStripe\Request\Api\Resource\DeleteInterface; use FluxSE\PayumStripe\Request\Api\Resource\DeletePlan; +use FluxSE\PayumStripe\Request\Api\Resource\DeleteProduct; use FluxSE\PayumStripe\Request\Api\Resource\OptionsAwareInterface; use FluxSE\PayumStripe\Request\Api\Resource\ResourceAwareInterface; use LogicException; @@ -14,7 +16,9 @@ use PHPUnit\Framework\TestCase; use Stripe\ApiOperations\Delete; use Stripe\ApiResource; +use Stripe\Coupon; use Stripe\Plan; +use Stripe\Product; final class DeleteTest extends TestCase { @@ -98,7 +102,9 @@ public function testNullApiResource(string $deleteRequestClass): void public function requestList(): array { return [ + [DeleteCoupon::class, Coupon::class], [DeletePlan::class, Plan::class], + [DeleteProduct::class, Product::class], ]; } } diff --git a/tests/Request/Api/Resource/RetrieveTest.php b/tests/Request/Api/Resource/RetrieveTest.php index 0c58561..bb9742d 100644 --- a/tests/Request/Api/Resource/RetrieveTest.php +++ b/tests/Request/Api/Resource/RetrieveTest.php @@ -12,6 +12,7 @@ use FluxSE\PayumStripe\Request\Api\Resource\RetrievePaymentIntent; use FluxSE\PayumStripe\Request\Api\Resource\RetrievePaymentMethod; use FluxSE\PayumStripe\Request\Api\Resource\RetrievePlan; +use FluxSE\PayumStripe\Request\Api\Resource\RetrievePrice; use FluxSE\PayumStripe\Request\Api\Resource\RetrieveProduct; use FluxSE\PayumStripe\Request\Api\Resource\RetrieveSession; use FluxSE\PayumStripe\Request\Api\Resource\RetrieveSetupIntent; @@ -28,6 +29,7 @@ use Stripe\PaymentIntent; use Stripe\PaymentMethod; use Stripe\Plan; +use Stripe\Price; use Stripe\Product; use Stripe\SetupIntent; use Stripe\Subscription; @@ -120,6 +122,7 @@ public function requestList(): array [RetrievePaymentIntent::class, PaymentIntent::class], [RetrievePaymentMethod::class, PaymentMethod::class], [RetrievePlan::class, Plan::class], + [RetrievePrice::class, Price::class], [RetrieveProduct::class, Product::class], [RetrieveSession::class, Session::class], [RetrieveSetupIntent::class, SetupIntent::class], diff --git a/tests/Request/Api/Resource/UpdateTest.php b/tests/Request/Api/Resource/UpdateTest.php index 31d3b40..6f3cce4 100644 --- a/tests/Request/Api/Resource/UpdateTest.php +++ b/tests/Request/Api/Resource/UpdateTest.php @@ -8,12 +8,20 @@ use FluxSE\PayumStripe\Request\Api\Resource\OptionsAwareInterface; use FluxSE\PayumStripe\Request\Api\Resource\ResourceAwareInterface; use FluxSE\PayumStripe\Request\Api\Resource\UpdateInterface; +use FluxSE\PayumStripe\Request\Api\Resource\UpdatePaymentIntent; +use FluxSE\PayumStripe\Request\Api\Resource\UpdatePlan; +use FluxSE\PayumStripe\Request\Api\Resource\UpdatePrice; +use FluxSE\PayumStripe\Request\Api\Resource\UpdateProduct; use FluxSE\PayumStripe\Request\Api\Resource\UpdateSubscription; use LogicException; use Payum\Core\Request\Generic; use PHPUnit\Framework\TestCase; use Stripe\ApiOperations\Update; use Stripe\ApiResource; +use Stripe\PaymentIntent; +use Stripe\Plan; +use Stripe\Price; +use Stripe\Product; use Stripe\Subscription; final class UpdateTest extends TestCase @@ -110,6 +118,10 @@ public function testGetSetParameters(string $updateRequestClass): void public function requestList(): array { return [ + [UpdatePaymentIntent::class, PaymentIntent::class], + [UpdatePlan::class, Plan::class], + [UpdatePrice::class, Price::class], + [UpdateProduct::class, Product::class], [UpdateSubscription::class, Subscription::class], ]; } diff --git a/tests/StripeGatewayFactoryTest.php b/tests/StripeGatewayFactoryTest.php index 15020fa..1b07b13 100644 --- a/tests/StripeGatewayFactoryTest.php +++ b/tests/StripeGatewayFactoryTest.php @@ -9,8 +9,10 @@ use FluxSE\PayumStripe\Action\StripeCheckoutSession; use FluxSE\PayumStripe\Action\StripeJs; use FluxSE\PayumStripe\Action\StripeJs\Api\RenderStripeJsAction; -use FluxSE\PayumStripe\Api\KeysAwareInterface; +use FluxSE\PayumStripe\Api\StripeCheckoutSessionApi; use FluxSE\PayumStripe\Api\StripeCheckoutSessionApiInterface; +use FluxSE\PayumStripe\Api\StripeClientAwareInterface; +use FluxSE\PayumStripe\Api\StripeJsApi; use FluxSE\PayumStripe\StripeCheckoutSessionGatewayFactory; use FluxSE\PayumStripe\StripeJsGatewayFactory; use Payum\Core\Bridge\Spl\ArrayObject; @@ -18,7 +20,6 @@ use Payum\Core\GatewayFactoryInterface; use PHPUnit\Framework\TestCase; use Stripe\PaymentIntent; - use function strpos; final class StripeGatewayFactoryTest extends TestCase @@ -175,8 +176,9 @@ public function testShouldAcceptDefaultOptions(string $gatewayClass): void ], 'payment_method_types' => ['card'], ]); + $newCredentials->defaults($config); $api = $config['payum.api']($newCredentials); - $this->assertInstanceOf(KeysAwareInterface::class, $api); + $this->assertInstanceOf(StripeClientAwareInterface::class, $api); } public function gatewayList(): array @@ -189,7 +191,14 @@ public function gatewayList(): array public function testConfigurationForCheckoutSession(): void { - $factory = new StripeCheckoutSessionGatewayFactory(); + $defaults = [ + 'publishable_key' => '12345', + 'secret_key' => '12345', + 'webhook_secret_keys' => [ + '12345' + ], + ]; + $factory = new StripeCheckoutSessionGatewayFactory($defaults); $config = $factory->createConfig(); @@ -213,11 +222,21 @@ public function testConfigurationForCheckoutSession(): void $this->assertEquals(new StripeCheckoutSession\Api\RedirectToCheckoutAction(), $actualActions['payum.action.redirect_to_checkout']); $this->assertArrayHasKey('payum.action.cancel.payment_intent.automatic', $actualActions); $this->assertEquals(new StripeCheckoutSession\CancelAction(), $actualActions['payum.action.cancel.payment_intent.automatic']); + + $api = $config['payum.api'](ArrayObject::ensureArrayObject($config)); + $this->assertInstanceOf(StripeCheckoutSessionApi::class, $api); } public function testConfigurationForStripeJs(): void { - $factory = new StripeJsGatewayFactory(); + $defaults = [ + 'publishable_key' => '12345', + 'secret_key' => '12345', + 'webhook_secret_keys' => [ + '12345' + ], + ]; + $factory = new StripeJsGatewayFactory($defaults); $config = $factory->createConfig(); @@ -244,8 +263,10 @@ public function testConfigurationForStripeJs(): void /** @var RenderStripeJsAction $payAction */ $payAction = $config['payum.action.render_stripe_js.payment_intent'](ArrayObject::ensureArrayObject($config)); $this->assertInstanceOf(RenderStripeJsAction::class, $payAction); - $this->assertEquals(PaymentIntent::class, $payAction->getApiResourceClass()); $this->assertEquals($config['payum.template.render_stripe_js.payment_intent'], $payAction->getTemplateName()); + + $api = $config['payum.api'](ArrayObject::ensureArrayObject($config)); + $this->assertInstanceOf(StripeJsApi::class, $api); } private function configuredPayumActions(array $config): array