Skip to content

Instantly share code, notes, and snippets.

@ger86
Last active March 7, 2019 10:41
Show Gist options
  • Save ger86/326fed77f9c012f830266a1417fadadc to your computer and use it in GitHub Desktop.
Save ger86/326fed77f9c012f830266a1417fadadc to your computer and use it in GitHub Desktop.
<?php
namespace App\Service;
use Stripe\Stripe;
use Stripe\Subscription;
final class StripeCreateSubscription {
/**
* @param string $stripeSecretApiKey
*/
public function __construct(string $stripeSecretApiKey) {
$this->stripeSecretApiKey = $stripeSecretApiKey;
}
/**
* Creates a Subscription
*
* @param string $email
* @param string $token
* @return Subscription
*/
public function __invoke(string $customerId, string $planId): Subscription {
Stripe::setApiKey($this->stripeSecretApiKey);
$subscription = Subscription::create([
'customer' => $customerId,
'items' => [['plan' => $planId]],
]);
return $subscription;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment