mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-02-05 02:48:56 +00:00
42 lines
933 B
PHP
42 lines
933 B
PHP
<?php
|
|
|
|
namespace App\Billing;
|
|
|
|
use Stripe\Charge;
|
|
use Stripe\Error\InvalidRequest;
|
|
|
|
class StripePaymentGateway implements PaymentGateway
|
|
{
|
|
private $apiKey;
|
|
|
|
public function __construct($apiKey)
|
|
{
|
|
$this->apiKey = $apiKey;
|
|
}
|
|
|
|
public function charge($amount, $token)
|
|
{
|
|
try {
|
|
Charge::create([
|
|
'amount' => $amount,
|
|
'source' => $token,
|
|
'currency' => 'usd',
|
|
], ['api_key' => $this->apiKey]);
|
|
} catch (InvalidRequest $e) {
|
|
throw new PaymentFailedException;
|
|
}
|
|
}
|
|
|
|
public function getValidTestToken()
|
|
{
|
|
return \Stripe\Token::create([
|
|
"card" => [
|
|
"number" => "4242424242424242",
|
|
"exp_month" => 1,
|
|
"exp_year" => date('Y') + 1,
|
|
"cvc" => "123"
|
|
]
|
|
], ['api_key' => $this->apiKey])->id;
|
|
}
|
|
}
|