Skip to content

Instantly share code, notes, and snippets.

@ger86
Last active March 7, 2019 10:40
Show Gist options
  • Save ger86/2b557b0d10b797c6405ce6b5c80f3ff5 to your computer and use it in GitHub Desktop.
Save ger86/2b557b0d10b797c6405ce6b5c80f3ff5 to your computer and use it in GitHub Desktop.
<?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