Skip to content

Instantly share code, notes, and snippets.

@ger86
Last active March 7, 2019 10:46
Show Gist options
  • Save ger86/3f37ee6c6e78af34a47929717e39333e to your computer and use it in GitHub Desktop.
Save ger86/3f37ee6c6e78af34a47929717e39333e to your computer and use it in GitHub Desktop.
<?php
namespace App\Service\Donation;
use Stripe\Plan;
use App\Enum\StripeConsts;
use App\Model\DTO\StripeCreatePlanDTO;
use App\Service\StripeCreateProduct;
use App\Service\StripeCreatePlan;
final class StripeCreateYearlyPlan {
/**
* Constructor
*
* @param StripeCreateProduct $stripeCreateProduct
* @param StripeCreatePlan $stripeCreatePlan
*/
public function __construct(
StripeCreateProduct $stripeCreateProduct,
StripeCreatePlan $stripeCreatePlan
) {
$this->stripeCreateProduct = $stripeCreateProduct;
$this->stripeCreatePlan = $stripeCreatePlan;
}
/**
* Creates a Stripe Plan
*
* @param string $planName
* @param float $amount
* @throws Exception
*/
public function __invoke(string $planName, float $amount) {
try {
$stripeProduct = ($this->stripeCreateProduct)($planName);
$dto = new StripeCreatePlanDTO(
StripeConsts::CURRENCY_EUR,
StripeConsts::INTERVAL_YEARLY,
$amount,
$stripeProduct->id
);
$stripePlan = ($this->stripeCreatePlan)($dto);
return $stripePlan;
} catch (\Exception $e) {
throw $e;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment