Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use StripeClient class #37

Merged
merged 4 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 !');
}

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

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

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();
}

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

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
23 changes: 23 additions & 0 deletions src/Action/Api/Resource/AllPlanAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace FluxSE\PayumStripe\Action\Api\Resource;

use FluxSE\PayumStripe\Request\Api\Resource\AllInterface;
use FluxSE\PayumStripe\Request\Api\Resource\AllPlan;
use Stripe\Service\AbstractService;
use Stripe\StripeClient;

final class AllPlanAction extends AbstractAllAction
{
public function getStripeService(StripeClient $stripeClient): AbstractService
{
return $stripeClient->plans;
}

public function supportAlso(AllInterface $request): bool
{
return $request instanceof AllPlan;
}
}
23 changes: 23 additions & 0 deletions src/Action/Api/Resource/AllPriceAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace FluxSE\PayumStripe\Action\Api\Resource;

use FluxSE\PayumStripe\Request\Api\Resource\AllInterface;
use FluxSE\PayumStripe\Request\Api\Resource\AllPrice;
use Stripe\Service\AbstractService;
use Stripe\StripeClient;

final class AllPriceAction extends AbstractAllAction
{
public function getStripeService(StripeClient $stripeClient): AbstractService
{
return $stripeClient->prices;
}

public function supportAlso(AllInterface $request): bool
{
return $request instanceof AllPrice;
}
}
23 changes: 23 additions & 0 deletions src/Action/Api/Resource/AllProductAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace FluxSE\PayumStripe\Action\Api\Resource;

use FluxSE\PayumStripe\Request\Api\Resource\AllInterface;
use FluxSE\PayumStripe\Request\Api\Resource\AllProduct;
use Stripe\Service\AbstractService;
use Stripe\StripeClient;

final class AllProductAction extends AbstractAllAction
{
public function getStripeService(StripeClient $stripeClient): AbstractService
{
return $stripeClient->products;
}

public function supportAlso(AllInterface $request): bool
{
return $request instanceof AllProduct;
}
}
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
Loading