Last active
March 7, 2019 10:40
-
-
Save ger86/2b557b0d10b797c6405ce6b5c80f3ff5 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 | |
use App\Model\DTO\StripeProcessSubscriptionDTO; | |
use App\Repository\StripePlanRepository; | |
use App\Service\StripeCreateCustomer; | |
use App\Service\StripeCreateSubscription; | |
final class StripeProcessSubscription { | |
/** | |
* @param StripeCreateCustomer $stripeCreateCustomer | |
* @param StripeCreateSubscription $stripeCreateSubscription | |
*/ | |
public function __construct( | |
StripePlanRepository $stripePlanRepo, | |
StripeCreateCustomer $stripeCreateCustomer, | |
StripeCreateSubscription $stripeCreateSubscription | |
) { | |
$this->stripePlanRepo = $stripePlanRepo; | |
$this->stripeCreateCustomer = $stripeCreateCustomer; | |
$this->stripeCreateSubscription = $stripeCreateSubscription; | |
} | |
/** | |
* Creates a Stripe Plan | |
* | |
* @param string $planName | |
* @param float $amount | |
* @throws Exception | |
*/ | |
public function __invoke(StripeProcessSubscriptionDTO $dto) { | |
try { | |
$customer = ($this->stripeCreateCustomer)($dto->getStripeEmail(), $dto->getStripeToken()); | |
$stripePlan = $this->stripePlanRepo->findOneById($dto->getPlanId()); | |
$subscription = ($this->stripeCreateSubscription)($customer->id, $stripePlan->getPlanId()); | |
} catch (\Exception $e) { | |
throw $e; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment