Skip to content

gateway capture $transactionReference = 0 Permanently #16

@MohamedFathiM

Description

@MohamedFathiM

this my code

  try {
            $creditCard = new \Omnipay\Common\CreditCard([
                'number' => $data['cardNumber'],
                'expiryMonth' => $data['expiration_month'],
                'expiryYear' => $data['expiration_year'],
                'cvv' => $data['cvv'],
            ]);

            $transactionId = 'ref' . time();

            $response = $this->gateway->authorize([
                'amount' => $data['amount'],
                'currency' => 'USD',
                'transactionId' => $transactionId,
                'card' => $creditCard,
                'customer_id' => auth()->user()->customer->id,
            ])->send();

            if ($response->isSuccessful()) {

                $transactionReference = $response->getTransactionReference();

                $response = $this->gateway->capture([
                    'amount' => $data['amount'],
                    'currency' => 'USD',
                    'transactionReference' => $transactionReference,
                ])->send();

                $transaction_id = $response->getTransactionReference();
                $paymentMethod = $response->getData()['transactionResponse']['accountType'];

                $isPaymentExist = Invoice::where('transaction_id', $transaction_id)->first();

                if (!$isPaymentExist) {
                    $payment = new Invoice();
                    $payment->price = $data['amount'];
                    $payment->transaction_id = $transaction_id;
                    $payment->order_id = $data['order_id'];
                    $payment->customer_id = auth()->user()->customer->id;
                    $payment->payment_date = date('yy/m/d');
                    $payment->payment_method = $paymentMethod ?? 'Online';
                    $payment->due_date = date('yy/m/d');
                    $payment->save();
                }

                return back()->with('success', "Payment is successful. Your transaction id is: " . $transaction_id);
            } else {
                // not successful
                return back()->withErrors(Lang::get($response->getMessage()));
            }
        } catch (Exception $e) {
            return back()->withErrors($e->getMessage());
        }

returned $transaction_id is always zero , the mode of authorize.net is test ,
Is that correct ?

[JDJ: edited for formatting]

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions