Skip to content

Instantly share code, notes, and snippets.

@ger86
Last active March 7, 2019 10:46
Show Gist options
  • Save ger86/92841486f540f3fa63550ebeadd3bfd6 to your computer and use it in GitHub Desktop.
Save ger86/92841486f540f3fa63550ebeadd3bfd6 to your computer and use it in GitHub Desktop.
<?php
namespace App\Service;
use Stripe\Stripe;
use Stripe\Product;
final class StripeCreateProduct {
/**
* @param string $stripeSecretApiKey
*/
public function __construct(string $stripeSecretApiKey) {
$this->stripeSecretApiKey = $stripeSecretApiKey;
}
/**
* Creates a Stripe Product
*
* @param string $name
* @param array $metadata
* @return Product
*
*/
public function __invoke(string $name, array $metadata = []): Product {
Stripe::setApiKey($this->stripeSecretApiKey);
$product = Product::create([
'name' => $name,
'type' => 'service',
'metadata' => $metadata
]);
return $product;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment