Skip to content

Commit 975e8ab

Browse files
committed
Fix Stripe
1 parent e6d882d commit 975e8ab

File tree

11 files changed

+214
-50
lines changed

11 files changed

+214
-50
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

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.

resources/js/components/Checkout/OrderCheckout.vue

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
<div>
33
<section class="mt-10">
44
<div v-if="localState.orderError" class="h-10 p-4">
5-
<span class="text-lg text-center text-red-500"
6-
>Error during order. Please retry</span
7-
>
5+
<span class="text-lg text-center text-red-500">Error during order. Please retry</span>
86
</div>
97
<div v-if="getCartQuantity">
108
<cart-summary />
@@ -21,8 +19,9 @@
2119
<div v-show="getCustomerDetails.firstName">
2220
<customer-details />
2321
<fakevisa-details />
24-
25-
<h2 class="h-10 p-4 mt-6 text-2xl font-bold text-center">Stripe payment</h2>
22+
<h2 class="h-10 p-4 mt-6 text-2xl font-bold text-center">
23+
Stripe payment
24+
</h2>
2625
<div class="flex justify-center w-full align-center">
2726
<div id="card-element" class="w-full h-16 mt-6 lg:w-5/12 xl:w-5/12">
2827
Stripe
@@ -33,10 +32,7 @@
3332
class="mt-6 px-6 py-2 font-semibold text-white rounded-md hover:opacity-90 transition-all duration-500 ease-in-out focus:outline-none bg-blue-600"
3433
:class="{
3534
disabledButton: localState.paymentIsProcessing,
36-
}"
37-
:disabled="localState.paymentIsProcessing"
38-
@click="checkout(product)"
39-
>
35+
}" :disabled="localState.paymentIsProcessing" @click="checkout(product)">
4036
Submit order
4137
</button>
4238
</div>
@@ -73,43 +69,37 @@ onMounted(async () => {
7369
7470
localState.cardElement = stripeElements.create("card", {
7571
classes: {
76-
base:
77-
"bg-gray-100 rounded border border-gray-300 focus:border-indigo-500 text-base outline-none text-gray-700 p-3 leading-8 transition-colors duration-200 ease-in-out",
72+
base: "bg-gray-100 rounded border border-gray-300 focus:border-indigo-500 text-base outline-none text-gray-700 p-3 leading-8 transition-colors duration-200 ease-in-out",
7873
},
7974
});
8075
8176
localState.cardElement.mount("#card-element");
8277
});
8378
8479
const checkout = async () => {
85-
const {
86-
firstName,
87-
lastName,
88-
address,
89-
zipcode,
90-
city,
91-
state,
92-
email,
93-
} = store.getCustomerDetails;
94-
95-
localState.paymentIsProcessing = true;
96-
97-
const { paymentMethod, error } = await localState.stripe.createPaymentMethod(
98-
"card",
99-
localState.cardElement,
100-
{
101-
billing_details: {
102-
name: `${firstName} ${lastName}`,
103-
email: email,
104-
address: {
105-
line1: address,
106-
city: city,
107-
state: state,
108-
postal_code: zipcode,
80+
const { firstName, lastName, address, zipcode, city, state, email } =
81+
store.getCustomerDetails;
82+
83+
//localState.paymentIsProcessing = true;
84+
localState.paymentIsProcessing = false;
85+
86+
const { paymentMethod, error } =
87+
await localState.stripe.createPaymentMethod(
88+
"card",
89+
localState.cardElement,
90+
{
91+
billing_details: {
92+
name: `${firstName} ${lastName}`,
93+
email: email,
94+
address: {
95+
line1: address,
96+
city: city,
97+
state: state,
98+
postal_code: zipcode,
99+
},
109100
},
110-
},
111-
}
112-
);
101+
}
102+
);
113103
114104
if (error || !paymentMethod.id) {
115105
localState.orderError = "Error";
@@ -133,6 +123,10 @@ const checkout = async () => {
133123
axios
134124
.post("/api/purchase", finalCustomerDetails)
135125
.then((response) => {
126+
127+
console.log("Response ..: ", response)
128+
129+
136130
if (response.statusText === "Created") {
137131
localState.paymentIsProcessing = false;
138132
store.clearCart();
@@ -159,11 +153,11 @@ const checkout = async () => {
159153
}
160154
161155
.item {
162-
@apply lg:m-2 xl:m-4 xl:w-1/6 lg:w-1/6 sm:m-2 w-auto;
156+
@apply lg: m-2 xl:m-4 xl:w-1/6 lg:w-1/6 sm:m-2 w-auto;
163157
}
164158
165159
.inline-block {
166-
@apply inline-block mt-4 lg:h-12 h-20 w-32 md:w-full lg:w-full xl:w-full;
160+
@apply inline-block mt-4 lg: h-12 h-20 w-32 md:w-full lg:w-full xl:w-full;
167161
}
168162
169163
.removing {

0 commit comments

Comments
 (0)