Files
ticketbeast/app/Billing/StripePaymentGateway.php
2017-01-17 19:57:34 -05:00

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;
}
}