Skip to content

Instantly share code, notes, and snippets.

@ger86
Last active March 7, 2019 10:46
Show Gist options
  • Save ger86/649aa060bf66547e453ec3c91dcee6b2 to your computer and use it in GitHub Desktop.
Save ger86/649aa060bf66547e453ec3c91dcee6b2 to your computer and use it in GitHub Desktop.
<?php
namespace App\Service\Stripe;
use Stripe\Stripe;
use Stripe\Plan;
use App\Model\DTO\StripeCreatePlanDTO;
use App\Service\StripeUtils;
final class StripeCreatePlan {
/**
* @param StripeUtils $stripeUtils
* @param string $stripeSecretApiKey
*/
public function __construct(StripeUtils $stripeUtils, string $stripeSecretApiKey) {
$this->stripeUtils = $stripeUtils;
$this->stripeSecretApiKey = $stripeSecretApiKey;
}
/**
* Creates a Stripe Plan
*
* @param StripeCreatePlanDTO $dto
* @return Plan
*/
public function __invoke(StripeCreatePlanDTO $dto): Plan {
Stripe::setApiKey($this->stripeSecretApiKey);
$amount = $this->stripeUtils->convertToStringAmount($dto->getAmount());
$plan = Plan::create([
'currency' => $dto->getCurrency(),
'interval' => $dto->getInterval(),
'product' => $dto->getProductId(),
'amount' => $amount
]);
return $plan;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment