wip: stripe implementation
- add model, dto
This commit is contained in:
parent
783ae6925b
commit
0799965212
@ -65,3 +65,6 @@ AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||
VITE_APP_NAME="${APP_NAME}"
|
||||
FRONTEND_URL=http://localhost:4200
|
||||
SANCTUM_STATEFUL_DOMAINS=localhost:4200
|
||||
|
||||
STRIPE_SECRET_KEY=sk_test_51TCvFrJG0RVtUg4VTqHZC2szosam9Mf0Nq0Sh71tdIKdld5DnOUhUl4VvFBZVRWPM9G5hLPNVmH8YNXqm2R6fR5U00fsEsLb1d
|
||||
STRIPE_WEBHOOK_KEY=
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
use App\Contracts\OutputDataTransferObject;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
final readonly class OrderResponeDTO implements OutputDataTransferObject
|
||||
final readonly class OrderCreatedResponseDTO implements OutputDataTransferObject
|
||||
{
|
||||
public function __construct(
|
||||
// TODO: Define your properties here
|
||||
35
backend/app/Data/StripeLineItemDTO.php
Normal file
35
backend/app/Data/StripeLineItemDTO.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Data;
|
||||
|
||||
use App\Contracts\OutputDataTransferObject;
|
||||
use App\Enums\StripeCurrency;
|
||||
|
||||
final readonly class StripeLineItemDTO implements OutputDataTransferObject
|
||||
{
|
||||
public function __construct(
|
||||
public StripeCurrency $currency,
|
||||
public int $price,
|
||||
public string $productName,
|
||||
public string $productDescription,
|
||||
public int $quantity
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return array<string, int|string>
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'price_data' => [
|
||||
'currency' => $this->currency->value,
|
||||
'unit_amount' => $this->price,
|
||||
'product_data' => [
|
||||
'name' => $this->productName,
|
||||
'description' => $this->productDescription,
|
||||
],
|
||||
],
|
||||
'quantity' => $this->quantity,
|
||||
];
|
||||
}
|
||||
}
|
||||
32
backend/app/Data/StripeSessionDataDTO.php
Normal file
32
backend/app/Data/StripeSessionDataDTO.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Data;
|
||||
|
||||
use App\Contracts\OutputDataTransferObject;
|
||||
use App\Enums\StripePaymentMode;
|
||||
|
||||
final readonly class StripeSessionDataDTO implements OutputDataTransferObject
|
||||
{
|
||||
/**
|
||||
* @param StripeLineItemDTO[] $lineItems
|
||||
*/
|
||||
public function __construct(
|
||||
public array $lineItems,
|
||||
public StripePaymentMode $mode,
|
||||
public string $successUrl,
|
||||
public string $cancelUrl
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'line_items' => array_map(fn (StripeLineItemDTO $dto) => $dto->toArray(), $this->lineItems),
|
||||
'mode' => $this->mode->value,
|
||||
'success_url' => $this->successUrl,
|
||||
'cancel_url' => $this->cancelUrl,
|
||||
];
|
||||
}
|
||||
}
|
||||
9
backend/app/Enums/StripeCurrency.php
Normal file
9
backend/app/Enums/StripeCurrency.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum StripeCurrency: string
|
||||
{
|
||||
case INR = 'inr';
|
||||
case USD = 'usd';
|
||||
}
|
||||
8
backend/app/Enums/StripePaymentMode.php
Normal file
8
backend/app/Enums/StripePaymentMode.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum StripePaymentMode: string
|
||||
{
|
||||
case Payment = 'payment';
|
||||
}
|
||||
@ -25,4 +25,9 @@ public function cart(): HasOne
|
||||
{
|
||||
return $this->hasOne(Cart::class);
|
||||
}
|
||||
|
||||
public function stripeSession(): HasOne
|
||||
{
|
||||
return $this->hasOne(StripeSession::class);
|
||||
}
|
||||
}
|
||||
|
||||
16
backend/app/Models/StripeSession.php
Normal file
16
backend/app/Models/StripeSession.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
class StripeSession extends Model
|
||||
{
|
||||
public $fillable = ['session_id', 'order_id'];
|
||||
|
||||
public function order(): HasOne
|
||||
{
|
||||
return $this->hasOne(Order::class);
|
||||
}
|
||||
}
|
||||
@ -35,4 +35,8 @@
|
||||
],
|
||||
],
|
||||
|
||||
'stripe' => [
|
||||
'secret' => env('STRIPE_SECRET_KEY'),
|
||||
'webhook' => env('STRIPE_WEBHOOK_KEY'),
|
||||
],
|
||||
];
|
||||
|
||||
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Order;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('stripe_sessions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('session_id');
|
||||
$table->foreignIdFor(Order::class)
|
||||
->constrained()
|
||||
->cascadeOnDelete();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('stripe_sessions');
|
||||
}
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user