Last active
March 7, 2019 10:46
-
-
Save ger86/3f37ee6c6e78af34a47929717e39333e 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\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