Skip to content

Instantly share code, notes, and snippets.

@abishekrsrikaanth
Created July 29, 2021 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abishekrsrikaanth/68e9d48be625d14ce53c147ee806a970 to your computer and use it in GitHub Desktop.
Save abishekrsrikaanth/68e9d48be625d14ce53c147ee806a970 to your computer and use it in GitHub Desktop.
<?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