mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-26 03:04:05 +00:00
55 - Making a Successful Charge
This commit is contained in:
24
app/Billing/StripePaymentGateway.php
Normal file
24
app/Billing/StripePaymentGateway.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Billing;
|
||||
|
||||
use Stripe\Charge;
|
||||
|
||||
class StripePaymentGateway implements PaymentGateway
|
||||
{
|
||||
private $apiKey;
|
||||
|
||||
public function __construct($apiKey)
|
||||
{
|
||||
$this->apiKey = $apiKey;
|
||||
}
|
||||
|
||||
public function charge($amount, $token)
|
||||
{
|
||||
Charge::create([
|
||||
'amount' => $amount,
|
||||
'source' => $token,
|
||||
'currency' => 'usd',
|
||||
], ['api_key' => $this->apiKey]);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Billing\StripePaymentGateway;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
@@ -10,7 +11,7 @@ class StripePaymentGatewayTest extends TestCase
|
||||
function charges_with_a_valid_payment_token_are_successful()
|
||||
{
|
||||
// Create a new StripePaymentGateway
|
||||
$paymentGateway = new StripePaymentGateway;
|
||||
$paymentGateway = new StripePaymentGateway(config('services.stripe.secret'));
|
||||
|
||||
$token = \Stripe\Token::create([
|
||||
"card" => [
|
||||
|
||||
Reference in New Issue
Block a user