Created
July 29, 2021 00:56
-
-
Save abishekrsrikaanth/68e9d48be625d14ce53c147ee806a970 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\Shared\Stripe; | |
use DomainException; | |
use Illuminate\Support\Facades\Log; | |
use Illuminate\Support\Str; | |
use Stripe\Exception\ApiErrorException; | |
use Stripe\Plan; | |
use Stripe\Product; | |
use Stripe\Stripe; | |
use Stripe\StripeClient; | |
class Stripe | |
{ | |
private StripeClient $client; | |
public function __construct() | |
{ | |
$this->client = new StripeClient(config('cashier.secret')); | |
} | |
public function createPlan($planName, $amount): Plan | |
{ | |
try { | |
return $this->client->plans->create([ | |
'amount' => $amount * 100, | |
'currency' => Str::lower(config('cashier.currency')), | |
'interval' => 'month', | |
'product' => [ | |
'name' => $planName, | |
], | |
]); | |
} catch (ApiErrorException $e) { | |
throw new DomainException('Error Creating Stripe Plan: '.$e->getMessage()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment