|
@@ -4,14 +4,11 @@ use App\Events\PaymentEvent;
|
|
use App\Events\UserUpdateCreditsEvent;
|
|
use App\Events\UserUpdateCreditsEvent;
|
|
use App\Models\PartnerDiscount;
|
|
use App\Models\PartnerDiscount;
|
|
use App\Models\Payment;
|
|
use App\Models\Payment;
|
|
-use App\Models\Product;
|
|
|
|
use App\Models\ShopProduct;
|
|
use App\Models\ShopProduct;
|
|
use App\Models\User;
|
|
use App\Models\User;
|
|
use App\Notifications\ConfirmPaymentNotification;
|
|
use App\Notifications\ConfirmPaymentNotification;
|
|
-use Illuminate\Http\RedirectResponse;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Auth;
|
|
-use Illuminate\Support\Facades\DB;
|
|
|
|
use Illuminate\Support\Facades\Redirect;
|
|
use Illuminate\Support\Facades\Redirect;
|
|
use Stripe\Exception\SignatureVerificationException;
|
|
use Stripe\Exception\SignatureVerificationException;
|
|
use Stripe\Stripe;
|
|
use Stripe\Stripe;
|
|
@@ -19,6 +16,7 @@ use Stripe\StripeClient;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @param Request $request
|
|
* @param Request $request
|
|
* @param ShopProduct $shopProduct
|
|
* @param ShopProduct $shopProduct
|
|
@@ -34,6 +32,8 @@ function StripePay(Request $request)
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ $discount = PartnerDiscount::getDiscount();
|
|
|
|
+
|
|
|
|
|
|
// create payment
|
|
// create payment
|
|
$payment = Payment::create([
|
|
$payment = Payment::create([
|
|
@@ -43,7 +43,7 @@ function StripePay(Request $request)
|
|
'type' => $shopProduct->type,
|
|
'type' => $shopProduct->type,
|
|
'status' => 'open',
|
|
'status' => 'open',
|
|
'amount' => $shopProduct->quantity,
|
|
'amount' => $shopProduct->quantity,
|
|
- 'price' => $shopProduct->price - ($shopProduct->price * PartnerDiscount::getDiscount() / 100),
|
|
|
|
|
|
+ 'price' => $shopProduct->price - ($shopProduct->price * $discount / 100),
|
|
'tax_value' => $shopProduct->getTaxValue(),
|
|
'tax_value' => $shopProduct->getTaxValue(),
|
|
'total_price' => $shopProduct->getTotalPrice(),
|
|
'total_price' => $shopProduct->getTotalPrice(),
|
|
'tax_percent' => $shopProduct->getTaxPercent(),
|
|
'tax_percent' => $shopProduct->getTaxPercent(),
|
|
@@ -58,7 +58,7 @@ function StripePay(Request $request)
|
|
'price_data' => [
|
|
'price_data' => [
|
|
'currency' => $shopProduct->currency_code,
|
|
'currency' => $shopProduct->currency_code,
|
|
'product_data' => [
|
|
'product_data' => [
|
|
- 'name' => $shopProduct->display . (PartnerDiscount::getDiscount() ? (' (' . __('Discount') . ' ' . PartnerDiscount::getDiscount() . '%)') : ''),
|
|
|
|
|
|
+ 'name' => $shopProduct->display . ($discount ? (' (' . __('Discount') . ' ' . $discount . '%)') : ''),
|
|
'description' => $shopProduct->description,
|
|
'description' => $shopProduct->description,
|
|
],
|
|
],
|
|
'unit_amount_decimal' => round($shopProduct->getPriceAfterDiscount() * 100, 2),
|
|
'unit_amount_decimal' => round($shopProduct->getPriceAfterDiscount() * 100, 2),
|
|
@@ -82,6 +82,11 @@ function StripePay(Request $request)
|
|
'payment_method_types' => str_getcsv(config('SETTINGS::PAYMENTS:STRIPE:METHODS')),
|
|
'payment_method_types' => str_getcsv(config('SETTINGS::PAYMENTS:STRIPE:METHODS')),
|
|
'success_url' => route('payment.StripeSuccess', ['payment' => $payment->id]) . '&session_id={CHECKOUT_SESSION_ID}',
|
|
'success_url' => route('payment.StripeSuccess', ['payment' => $payment->id]) . '&session_id={CHECKOUT_SESSION_ID}',
|
|
'cancel_url' => route('payment.Cancel'),
|
|
'cancel_url' => route('payment.Cancel'),
|
|
|
|
+ 'payment_intent_data' => [
|
|
|
|
+ 'metadata' => [
|
|
|
|
+ 'payment_id' => $payment->id,
|
|
|
|
+ ],
|
|
|
|
+ ],
|
|
]);
|
|
]);
|
|
|
|
|
|
Redirect::to($request->url)->send();
|
|
Redirect::to($request->url)->send();
|
|
@@ -98,6 +103,8 @@ function StripeSuccess(Request $request)
|
|
$shopProduct = ShopProduct::findOrFail($payment->shop_item_product_id);
|
|
$shopProduct = ShopProduct::findOrFail($payment->shop_item_product_id);
|
|
|
|
|
|
|
|
|
|
|
|
+ Redirect::route('home')->with('success', 'Please wait for success')->send();
|
|
|
|
+
|
|
$stripeClient = getStripeClient();
|
|
$stripeClient = getStripeClient();
|
|
try {
|
|
try {
|
|
//get stripe data
|
|
//get stripe data
|
|
@@ -162,16 +169,17 @@ function StripeSuccess(Request $request)
|
|
function handleStripePaymentSuccessHook($paymentIntent)
|
|
function handleStripePaymentSuccessHook($paymentIntent)
|
|
{
|
|
{
|
|
try {
|
|
try {
|
|
- // Get payment db entry
|
|
|
|
- $payment = Payment::where('payment_id', $paymentIntent->id)->first();
|
|
|
|
|
|
+ $payment = Payment::where('id', $paymentIntent->metadata->payment_id)->with('user')->first();
|
|
$user = User::where('id', $payment->user_id)->first();
|
|
$user = User::where('id', $payment->user_id)->first();
|
|
$shopProduct = ShopProduct::findOrFail($payment->shop_item_product_id);
|
|
$shopProduct = ShopProduct::findOrFail($payment->shop_item_product_id);
|
|
|
|
|
|
if ($paymentIntent->status == 'succeeded' && $payment->status == 'processing') {
|
|
if ($paymentIntent->status == 'succeeded' && $payment->status == 'processing') {
|
|
|
|
|
|
-
|
|
|
|
//update payment db entry status
|
|
//update payment db entry status
|
|
- $payment->update(['status' => 'paid']);
|
|
|
|
|
|
+ $payment->update([
|
|
|
|
+ 'payment_id' => $payment->payment_id ?? $paymentIntent->id,
|
|
|
|
+ 'status' => 'paid'
|
|
|
|
+ ]);
|
|
|
|
|
|
//payment notification
|
|
//payment notification
|
|
$user->notify(new ConfirmPaymentNotification($payment));
|
|
$user->notify(new ConfirmPaymentNotification($payment));
|