Skip to content

Commit b864c71

Browse files
authored
Merge pull request #885 from w3bdesign/dev
Fix Stripe payment not working
2 parents 4df65b9 + 7071358 commit b864c71

File tree

12 files changed

+215
-51
lines changed

12 files changed

+215
-51
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
5353

5454
STRIPE_KEY="changeme"
5555
STRIPE_SECRET="changeme"
56+
STRIPE_WEBHOOK_SECRET="changeme"
5657

5758
MIX_STRIPE_KEY="${STRIPE_KEY}"
5859

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Ecommerce site with Laravel 10, Vue 3 and Stripe.
4545

4646
- Fork or clone the project
4747

48-
- Ensure you have PHP 8.2.4 or newer installed and setup properly (alternatively use Docker, see <https://laravel.com/docs/9.x/sail>)
48+
- Ensure you have PHP 8.2.4 or newer installed and setup properly (alternatively use Docker, see <https://laravel.com/docs/10.x/sail>)
4949

5050
- Ensure you have access to a PostgreSQL database
5151

app/Http/Controllers/Api/UserController.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function purchase(Request $request)
1818
],
1919
[
2020
'password' => Hash::make(Str::random(12)),
21-
'name' => $request->input('first_name').' '.$request->input('last_name'),
21+
'name' => $request->input('first_name') . ' ' . $request->input('last_name'),
2222
'address' => $request->input('address'),
2323
'city' => $request->input('city'),
2424
'state' => $request->input('state'),
@@ -36,9 +36,11 @@ public function purchase(Request $request)
3636

3737
$order = $user->orders()
3838
->create([
39-
'transaction_id' => $payment->charges->data[0]->id,
40-
'total' => $payment->charges->data[0]->amount,
39+
'transaction_id' => $payment->id,
40+
'total' => $payment->amount,
4141
]);
42+
43+
4244
foreach (json_decode($request->input('cart'), true) as $item) {
4345
$order->products()
4446
->attach($item['id'], ['quantity' => $item['quantity']]);

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"require": {
1111
"php": "8.2.4",
1212
"guzzlehttp/guzzle": "7.7.0",
13-
"laravel/cashier": "v14.12.1",
13+
"laravel/cashier": "^14.12",
1414
"laravel/framework": "v10.11.0",
1515
"laravel/sanctum": "v3.2.5",
1616
"laravel/tinker": "v2.8.1"

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('users', function (Blueprint $table) {
15+
$table->string('stripe_id')->nullable()->index();
16+
$table->string('pm_type')->nullable();
17+
$table->string('pm_last_four', 4)->nullable();
18+
$table->timestamp('trial_ends_at')->nullable();
19+
});
20+
}
21+
22+
/**
23+
* Reverse the migrations.
24+
*/
25+
public function down(): void
26+
{
27+
Schema::table('users', function (Blueprint $table) {
28+
$table->dropColumn([
29+
'stripe_id',
30+
'pm_type',
31+
'pm_last_four',
32+
'trial_ends_at',
33+
]);
34+
});
35+
}
36+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('subscriptions', function (Blueprint $table) {
15+
$table->id();
16+
$table->foreignId('user_id');
17+
$table->string('name');
18+
$table->string('stripe_id')->unique();
19+
$table->string('stripe_status');
20+
$table->string('stripe_price')->nullable();
21+
$table->integer('quantity')->nullable();
22+
$table->timestamp('trial_ends_at')->nullable();
23+
$table->timestamp('ends_at')->nullable();
24+
$table->timestamps();
25+
26+
$table->index(['user_id', 'stripe_status']);
27+
});
28+
}
29+
30+
/**
31+
* Reverse the migrations.
32+
*/
33+
public function down(): void
34+
{
35+
Schema::dropIfExists('subscriptions');
36+
}
37+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('subscription_items', function (Blueprint $table) {
15+
$table->id();
16+
$table->foreignId('subscription_id');
17+
$table->string('stripe_id')->unique();
18+
$table->string('stripe_product');
19+
$table->string('stripe_price');
20+
$table->integer('quantity')->nullable();
21+
$table->timestamps();
22+
23+
$table->unique(['subscription_id', 'stripe_price']);
24+
});
25+
}
26+
27+
/**
28+
* Reverse the migrations.
29+
*/
30+
public function down(): void
31+
{
32+
Schema::dropIfExists('subscription_items');
33+
}
34+
};

public/css/app.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,10 @@ video {
667667
margin: 1rem;
668668
}
669669

670+
.m-2 {
671+
margin: 0.5rem;
672+
}
673+
670674
.mx-auto {
671675
margin-left: auto;
672676
margin-right: auto;

public/js/app.js

Lines changed: 57 additions & 4 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)