Skip to content

Commit

Permalink
Use StripeClient class
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometee committed Sep 19, 2023
1 parent be39460 commit 080833c
Show file tree
Hide file tree
Showing 68 changed files with 492 additions and 199 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"require": {
"payum/core": "^1.6",
"stripe/stripe-php": "^9"
"stripe/stripe-php": "^12"
},
"require-dev": {
"phpunit/phpunit": "^8|^9",
Expand Down
21 changes: 18 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>, mixed given\./'
message: '/Parameter #3 \$webhookSecretKeys of class FluxSE\\PayumStripe\\Api\\Stripe(CheckoutSession|Js)Api constructor expects array<string>, 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\./'
Expand Down
4 changes: 4 additions & 0 deletions src/AbstractStripeGatewayFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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,
];
}

Expand Down
13 changes: 4 additions & 9 deletions src/Action/Api/Resource/AbstractAllAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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 !');

Check warning on line 37 in src/Action/Api/Resource/AbstractAllAction.php

View check run for this annotation

Codecov / codecov/patch

src/Action/Api/Resource/AbstractAllAction.php#L37

Added line #L37 was not covered by tests
}

Stripe::setApiKey($this->api->getSecretKey());

/* @see All::all() */
return $apiResourceClass::all(
return $service->all(
$request->getParameters(),
$request->getOptions()
);
Expand Down
13 changes: 4 additions & 9 deletions src/Action/Api/Resource/AbstractCreateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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 !');

Check warning on line 37 in src/Action/Api/Resource/AbstractCreateAction.php

View check run for this annotation

Codecov / codecov/patch

src/Action/Api/Resource/AbstractCreateAction.php#L37

Added line #L37 was not covered by tests
}

Stripe::setApiKey($this->api->getSecretKey());

/* @see Create::create() */
return $apiResourceClass::create(
return $service->create(
$request->getParameters(),
$request->getOptions()
);
Expand Down
19 changes: 6 additions & 13 deletions src/Action/Api/Resource/AbstractDeleteAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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 !');

Check warning on line 34 in src/Action/Api/Resource/AbstractDeleteAction.php

View check run for this annotation

Codecov / codecov/patch

src/Action/Api/Resource/AbstractDeleteAction.php#L34

Added line #L34 was not covered by tests
}

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 !');

Check warning on line 38 in src/Action/Api/Resource/AbstractDeleteAction.php

View check run for this annotation

Codecov / codecov/patch

src/Action/Api/Resource/AbstractDeleteAction.php#L38

Added line #L38 was not covered by tests
}

Stripe::setApiKey($this->api->getSecretKey());

/** @see Retrieve::retrieve() */
$apiResource = $apiResourceClass::retrieve(
$apiResource = $service->retrieve(
$request->getId(),
$request->getOptions()
);

/* @see Delete::delete() */
return $apiResource->delete();
}

Expand Down
13 changes: 4 additions & 9 deletions src/Action/Api/Resource/AbstractRetrieveAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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 !');
}

Check warning on line 35 in src/Action/Api/Resource/AbstractRetrieveAction.php

View check run for this annotation

Codecov / codecov/patch

src/Action/Api/Resource/AbstractRetrieveAction.php#L34-L35

Added lines #L34 - L35 were not covered by tests

Stripe::setApiKey($this->api->getSecretKey());

/* @see Retrieve::retrieve() */
return $apiResourceClass::retrieve(
return $service->retrieve(
$request->getId(),
$request->getOptions()
);
Expand Down
14 changes: 5 additions & 9 deletions src/Action/Api/Resource/AbstractUpdateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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()
Expand Down
8 changes: 6 additions & 2 deletions src/Action/Api/Resource/AllCouponAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
8 changes: 6 additions & 2 deletions src/Action/Api/Resource/AllCustomerAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
8 changes: 6 additions & 2 deletions src/Action/Api/Resource/AllInvoiceAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
8 changes: 6 additions & 2 deletions src/Action/Api/Resource/AllSessionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
8 changes: 6 additions & 2 deletions src/Action/Api/Resource/AllTaxRateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
7 changes: 6 additions & 1 deletion src/Action/Api/Resource/CancelPaymentIntentAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
7 changes: 6 additions & 1 deletion src/Action/Api/Resource/CancelSetupIntentAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
7 changes: 6 additions & 1 deletion src/Action/Api/Resource/CancelSubscriptionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
7 changes: 6 additions & 1 deletion src/Action/Api/Resource/CapturePaymentIntentAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Loading

0 comments on commit 080833c

Please sign in to comment.