Last active
March 7, 2019 10:46
-
-
Save ger86/649aa060bf66547e453ec3c91dcee6b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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