Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gateway capture $transactionReference = 0 Permanently #16

Open
MohamedFathiM opened this issue Apr 23, 2020 · 3 comments
Open

gateway capture $transactionReference = 0 Permanently #16

MohamedFathiM opened this issue Apr 23, 2020 · 3 comments
Assignees

Comments

@MohamedFathiM
Copy link

MohamedFathiM commented Apr 23, 2020

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]

@judgej
Copy link
Member

judgej commented Apr 24, 2020

Just seen this and noted. Will get back to you ASAP.

@judgej judgej self-assigned this Apr 26, 2020
@judgej
Copy link
Member

judgej commented Apr 26, 2020

That essentially is correct and is how I have some test scripts successfuly running. The transaction reference and ID look like they may be a little mixed up on the middle, but I don't know enough about your database to say for sure.

The response to the initial authorize will return a transactionReference generated by the gateway. That trancationReference is then passed to the capture endpoint. The same transactionReference is then returned with the response to that (you then call it transaction_id at this point for looking it up on your persistent payment storage). The response to the capture will also return the same transactionReference.

On the gateway response, the transId (the capture) and the refTransId (the transaction being captured) are one and the same. Fir a void or refund, I believe they will differ, since those would be separate transactions.

@MohamedFathiM
Copy link
Author

thank you , it is clear

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants