mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-26 03:04:05 +00:00
57 - Don't Mock What You Don't Own
This commit is contained in:
24
app/Billing/Alternate/StripePaymentGateway.php
Normal file
24
app/Billing/Alternate/StripePaymentGateway.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Billing\Alternate;
|
||||
|
||||
use App\Billing\PaymentGateway;
|
||||
|
||||
class StripePaymentGateway implements PaymentGateway
|
||||
{
|
||||
private $stripeClient;
|
||||
|
||||
public function __construct(\Stripe\ApiClient $stripeClient)
|
||||
{
|
||||
$this->stripeClient = $stripeClient;
|
||||
}
|
||||
|
||||
public function charge($amount, $token)
|
||||
{
|
||||
$this->stripeClient->createCharge([
|
||||
'amount' => $amount,
|
||||
'source' => $token,
|
||||
'currency' => 'usd',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -22,3 +22,27 @@ class StripePaymentGateway implements PaymentGateway
|
||||
], ['api_key' => $this->apiKey]);
|
||||
}
|
||||
}
|
||||
|
||||
// class StripePaymentGateway implements PaymentGateway
|
||||
// {
|
||||
// private $apiKey;
|
||||
|
||||
// public function __construct($apiKey)
|
||||
// {
|
||||
// $this->apiKey = $apiKey;
|
||||
// }
|
||||
|
||||
// public function charge($amount, $token)
|
||||
// {
|
||||
// (new \GuzzleHttp\Client)->post('https://api.stripe.com/v1/charges', [
|
||||
// 'headers' => [
|
||||
// 'Authorization' => "Bearer {$this->apiKey}",
|
||||
// ],
|
||||
// 'form_params' => [
|
||||
// 'amount' => $amount,
|
||||
// 'token' => $token,
|
||||
// 'currency' => 'usd',
|
||||
// ]
|
||||
// ]);
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
"php": ">=5.6.4",
|
||||
"laravel/framework": "5.3.*",
|
||||
"zondicons/blade-bridge": "^0.1.0",
|
||||
"stripe/stripe-php": "^4.3"
|
||||
"stripe/stripe-php": "^4.3",
|
||||
"guzzlehttp/guzzle": "^6.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"fzaninotto/faker": "~1.4",
|
||||
|
||||
225
composer.lock
generated
225
composer.lock
generated
@@ -4,8 +4,8 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"hash": "8cdff7401ffaa77e712fc773720a0a25",
|
||||
"content-hash": "4283a0ebb9e0602a14c02b45b50cb2d7",
|
||||
"hash": "483f8274bdccb5d6398c5c9b7607e8e2",
|
||||
"content-hash": "cf64a65c2814f1dab2944cbf2f70101d",
|
||||
"packages": [
|
||||
{
|
||||
"name": "classpreloader/classpreloader",
|
||||
@@ -161,6 +161,177 @@
|
||||
],
|
||||
"time": "2015-11-06 14:35:42"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/guzzle",
|
||||
"version": "6.2.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/guzzle.git",
|
||||
"reference": "ebf29dee597f02f09f4d5bbecc68230ea9b08f60"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/ebf29dee597f02f09f4d5bbecc68230ea9b08f60",
|
||||
"reference": "ebf29dee597f02f09f4d5bbecc68230ea9b08f60",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"guzzlehttp/promises": "^1.0",
|
||||
"guzzlehttp/psr7": "^1.3.1",
|
||||
"php": ">=5.5"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-curl": "*",
|
||||
"phpunit/phpunit": "^4.0",
|
||||
"psr/log": "^1.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "6.2-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"src/functions_include.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"GuzzleHttp\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Michael Dowling",
|
||||
"email": "mtdowling@gmail.com",
|
||||
"homepage": "https://github.com/mtdowling"
|
||||
}
|
||||
],
|
||||
"description": "Guzzle is a PHP HTTP client library",
|
||||
"homepage": "http://guzzlephp.org/",
|
||||
"keywords": [
|
||||
"client",
|
||||
"curl",
|
||||
"framework",
|
||||
"http",
|
||||
"http client",
|
||||
"rest",
|
||||
"web service"
|
||||
],
|
||||
"time": "2016-10-08 15:01:37"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/promises",
|
||||
"version": "v1.3.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/promises.git",
|
||||
"reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646",
|
||||
"reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.5.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.4-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"GuzzleHttp\\Promise\\": "src/"
|
||||
},
|
||||
"files": [
|
||||
"src/functions_include.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Michael Dowling",
|
||||
"email": "mtdowling@gmail.com",
|
||||
"homepage": "https://github.com/mtdowling"
|
||||
}
|
||||
],
|
||||
"description": "Guzzle promises library",
|
||||
"keywords": [
|
||||
"promise"
|
||||
],
|
||||
"time": "2016-12-20 10:07:11"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/psr7",
|
||||
"version": "1.3.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/psr7.git",
|
||||
"reference": "5c6447c9df362e8f8093bda8f5d8873fe5c7f65b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/psr7/zipball/5c6447c9df362e8f8093bda8f5d8873fe5c7f65b",
|
||||
"reference": "5c6447c9df362e8f8093bda8f5d8873fe5c7f65b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.4.0",
|
||||
"psr/http-message": "~1.0"
|
||||
},
|
||||
"provide": {
|
||||
"psr/http-message-implementation": "1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.4-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"GuzzleHttp\\Psr7\\": "src/"
|
||||
},
|
||||
"files": [
|
||||
"src/functions_include.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Michael Dowling",
|
||||
"email": "mtdowling@gmail.com",
|
||||
"homepage": "https://github.com/mtdowling"
|
||||
}
|
||||
],
|
||||
"description": "PSR-7 message implementation",
|
||||
"keywords": [
|
||||
"http",
|
||||
"message",
|
||||
"stream",
|
||||
"uri"
|
||||
],
|
||||
"time": "2016-06-24 23:00:38"
|
||||
},
|
||||
{
|
||||
"name": "jakub-onderka/php-console-color",
|
||||
"version": "0.1",
|
||||
@@ -828,6 +999,56 @@
|
||||
],
|
||||
"time": "2016-10-17 15:23:22"
|
||||
},
|
||||
{
|
||||
"name": "psr/http-message",
|
||||
"version": "1.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/http-message.git",
|
||||
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
|
||||
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Psr\\Http\\Message\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "PHP-FIG",
|
||||
"homepage": "http://www.php-fig.org/"
|
||||
}
|
||||
],
|
||||
"description": "Common interface for HTTP messages",
|
||||
"homepage": "https://github.com/php-fig/http-message",
|
||||
"keywords": [
|
||||
"http",
|
||||
"http-message",
|
||||
"psr",
|
||||
"psr-7",
|
||||
"request",
|
||||
"response"
|
||||
],
|
||||
"time": "2016-08-06 14:39:51"
|
||||
},
|
||||
{
|
||||
"name": "psr/log",
|
||||
"version": "1.0.2",
|
||||
|
||||
21
tests/unit/Billing/MockStripePaymentGatewayTest.php
Normal file
21
tests/unit/Billing/MockStripePaymentGatewayTest.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use App\Billing\Alternate\StripePaymentGateway;
|
||||
|
||||
class MockStripePaymentGatewayTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
function charges_with_a_valid_payment_token_are_successful()
|
||||
{
|
||||
$stripeClient = Mockery::spy(\Stripe\ApiClient::class);
|
||||
$paymentGateway = new StripePaymentGateway($stripeClient);
|
||||
|
||||
$paymentGateway->charge(2500, 'valid-token');
|
||||
|
||||
$stripeClient->shouldHaveReceived('createCharge')->with([
|
||||
'amount' => 2500,
|
||||
'source' => 'valid-token',
|
||||
'currency' => 'usd',
|
||||
])->once();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Billing\StripePaymentGateway;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class StripePaymentGatewayTest extends TestCase
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user