%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/forge/api-takeaseat.eco-n-tech.co.uk/app/Jobs/
Upload File :
Create Path :
Current File : //home/forge/api-takeaseat.eco-n-tech.co.uk/app/Jobs/CollectPayment.php

<?php

namespace App\Jobs;

use App\Models\Payment;
use App\Helpers\MoneyHelper;
use Illuminate\Bus\Queueable;
use App\Services\Stripe\SellerService;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class CollectPayment implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    
    /**
     * @var Payment
     */
    protected $payment;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(Payment $payment)
    {
        $this->payment = $payment;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        if($this->payment->is_complete == false) {
            $paymentMethod = $this->payment->user->defaultPaymentMethod();
            $amount = MoneyHelper::stripeFormat($this->payment->amount + $this->payment->fees_collected);
            $payment = $this->payment->user->charge($amount, $paymentMethod->id, [
                'off_session' => true,
                'confirm' => true
            ]);

            $this->payment->update(['is_complete' => true]);
            
            if($this->payment->seller->stripe_connect_id !== null) {
                $charges = $payment->asStripePaymentIntent();

                foreach($charges['charges']['data'] as $charge) {
                    $fees = MoneyHelper::getStripeFees(($this->payment->amount + $this->payment->fees_collected), $charge['payment_method_details']['card']['country']);
                    $transfer_amount = MoneyHelper::stripeFormat($this->payment->amount - $fees);
                    $transfer = SellerService::createTransfer($this->payment->seller, $transfer_amount, $charge['id']);
                    
                    $this->payment->transfer()->create([
                        'payment_id' => $this->payment->id,
                        'transfer_id' => $transfer['id']
                    ]);

                    $this->payment->charges()->create([
                        'payment_id' => $this->payment->id,
                        'charge_id' => $charge['id']
                    ]);
                }
            }
        }
    }
}

Zerion Mini Shell 1.0