55 - Making a Successful Charge

This commit is contained in:
Adam Wathan
2016-12-29 20:41:29 -05:00
parent d8f86c568d
commit 3acda11372
2 changed files with 26 additions and 1 deletions

View 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]);
}
}

View File

@@ -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" => [