feat: modified db payment table

This commit is contained in:
IceToast 2021-12-15 11:41:57 +01:00
parent 1d72bac7fa
commit 34a8d566a7
5 changed files with 603 additions and 25 deletions

View file

@ -177,7 +177,7 @@ class PaymentController extends Controller
$payment = Payment::create([ $payment = Payment::create([
'user_id' => $user->id, 'user_id' => $user->id,
'payment_id' => $response->result->id, 'payment_id' => $response->result->id,
'payer_id' => $laravelRequest->input('PayerID'), 'payment_method' => 'paypal',
'type' => 'Credits', 'type' => 'Credits',
'status' => $response->result->status, 'status' => $response->result->status,
'amount' => $creditProduct->quantity, 'amount' => $creditProduct->quantity,
@ -186,7 +186,6 @@ class PaymentController extends Controller
'tax_percent' => $creditProduct->getTaxPercent(), 'tax_percent' => $creditProduct->getTaxPercent(),
'total_price' => $creditProduct->getTotalPrice(), 'total_price' => $creditProduct->getTotalPrice(),
'currency_code' => $creditProduct->currency_code, 'currency_code' => $creditProduct->currency_code,
'payer' => json_encode($response->result->payer),
]); ]);
//payment notification //payment notification
@ -236,7 +235,7 @@ class PaymentController extends Controller
$stripeClient = $this->getStripeClient(); $stripeClient = $this->getStripeClient();
$request = $stripeClient->sessions->create([ $request = $stripeClient->checkout->sessions->create([
'line_items' => [ 'line_items' => [
[ [
'price_data' => [ 'price_data' => [
@ -280,7 +279,6 @@ class PaymentController extends Controller
*/ */
public function StripeSuccess(Request $request) public function StripeSuccess(Request $request)
{ {
echo $request->input('product');
/** @var CreditProduct $creditProduct */ /** @var CreditProduct $creditProduct */
$creditProduct = CreditProduct::findOrFail($request->input('product')); $creditProduct = CreditProduct::findOrFail($request->input('product'));
@ -289,12 +287,11 @@ class PaymentController extends Controller
$stripeClient = $this->getStripeClient(); $stripeClient = $this->getStripeClient();
try{ try{
$paymentSession = $stripeClient->sessions->retrieve($request->input('session_id')); $paymentSession = $stripeClient->checkout->sessions->retrieve($request->input('session_id'));
$capturedPaymentIntent = $stripeClient->paymentIntents->capture($paymentSession.payment_intent); $capturedPaymentIntent = $stripeClient->paymentIntents->capture($paymentSession->payment_intent);
if ($response->payment_status == "paid") { if ($capturedPaymentIntent->status == "succeeded") {
//update credits //update credits
$user->increment('credits', $creditProduct->quantity); $user->increment('credits', $creditProduct->quantity);
@ -314,17 +311,16 @@ class PaymentController extends Controller
//store payment //store payment
$payment = Payment::create([ $payment = Payment::create([
'user_id' => $user->id, 'user_id' => $user->id,
'payment_id' => $response->result->id, 'payment_id' => $capturedPaymentIntent->id,
'payer_id' => $request->input('PayerID'), 'payment_method' => 'stripe',
'type' => 'Credits', 'type' => 'Credits',
'status' => $response->payment_status, 'status' => $capturedPaymentIntent->status,
'amount' => $creditProduct->quantity, 'amount' => $creditProduct->quantity,
'price' => $creditProduct->price, 'price' => $creditProduct->price,
'tax_value' => $creditProduct->getTaxValue(), 'tax_value' => $creditProduct->getTaxValue(),
'tax_percent' => $creditProduct->getTaxPercent(),
'total_price' => $creditProduct->getTotalPrice(), 'total_price' => $creditProduct->getTotalPrice(),
'tax_percent' => $creditProduct->getTaxPercent(),
'currency_code' => $creditProduct->currency_code, 'currency_code' => $creditProduct->currency_code,
'payer' => json_encode($response->result->payer),
]); ]);
//payment notification //payment notification

View file

@ -23,8 +23,7 @@ class Payment extends Model
'id', 'id',
'user_id', 'user_id',
'payment_id', 'payment_id',
'payer_id', 'payment_method',
'payer',
'status', 'status',
'type', 'type',
'amount', 'amount',

View file

@ -17,12 +17,11 @@ class CreatePaymentsTable extends Migration
$table->uuid('id'); $table->uuid('id');
$table->foreignId('user_id')->references('id')->on('users'); $table->foreignId('user_id')->references('id')->on('users');
$table->string('payment_id')->nullable(); $table->string('payment_id')->nullable();
$table->string('payer_id')->nullable();; $table->string('payment_method')->nullable();
$table->string('type')->nullable();; $table->string('type')->nullable();;
$table->string('status')->nullable();; $table->string('status')->nullable();;
$table->string('amount')->nullable();; $table->string('amount')->nullable();;
$table->string('price')->nullable();; $table->string('price')->nullable();;
$table->text('payer')->nullable();;
$table->timestamps(); $table->timestamps();
}); });
} }

29
public/css/app.css vendored

File diff suppressed because one or more lines are too long

569
public/js/app.js vendored

File diff suppressed because one or more lines are too long