Transaction Id


#1

Where can I find the transcationId if I do the payments manually?


#2

You can capture the transaction id with the following call:

curl -X POST https://api.moltin.com/v2/orders/:orderId/transactions/:transaction_id/capture \
     -H "Authorization: Bearer XXXX"

The transaction id should be returned in the body from the authorization call.

We have a great resource at https://developers.moltin.com/guides/payment/implement-own-payment-gateway that explains how to use the manual gateway.

Thank you

Drew


#3

Hi @drew

I am using that docs you send, will the transactionId be automatically generated?
because unlike the orderId that I get in a response and then use in the parameter, I can’t find any responses were the transactionId is displayed?


#4

will that be manually entered?

for example the payment is received outside of moltin and then I have to give the transaction a ID? received from payment gate?


#5

Hey Handre,

Yes, you would get the transaction id from your payment gateway and capture it with the above curl request I posted.

Thanks

Drew


#6

Hi @drew

I am getting a 401 error.

here is my api call:

finishOrder(orderId, transactionId) {
    return this.http.post(
      `${this.uri}/v2/orders/${orderId}/transactions/${transactionId}/capture`,
      { headers: new HttpHeaders().set('Authorization', 'Bearer ' + localStorage.getItem('auth')) }
    );
  }

#7

Hi, @handre do you have the message returned from the API?

Thanks

Drew


#8

The response is the following {status: 401, title: "Unable to validate access token"}

Are you sure that the transactionId must be inserted manually, through the header?


#9

Hi @handre this issue looks like it isn’t related to the URL and rather its to do with the access token. Can you show me full call payload being made the API?

Thanks

Drew


#10

ts. file

onCompletes(transactionId) {
    this.route.paramMap.pipe(
      switchMap((params: ParamMap) =>
        this.mhttp.finishOrder(params.get('id'), transactionId)
      ))
      .subscribe(response => {
        console.log(response);
      });
  }

html form:

<form [formGroup]="completeOrder" (ngSubmit)="onCompletes(completeOrder.value)">
              <div class="form-group">
                <input type="text" id="transactionId" class="form-control" formControlName="transactionId" placeholder="Unique ID for this order"
                  required>
              </div>
              <button type="submit" class="btn btn-lg btn-block" value="Submit Form">Clear Order</button>
            </form>

#11

Thanks @handre can you show me what is being sent to the API from the Dev console?


#12

POST https://api.moltin.com/v2/orders/f4c5d354-4ffb-4082-8103-901baed9c429/transactions/[object%20Object]/capture 401 (Unauthorized)


#13

@drew
I got the correct header info to be send. I still get a 401 error:

POST https://api.moltin.com/v2/orders/f4c5d354-4ffb-4082-8103-901baed9c429/transactions/1245/capture 401 (Unauthorized)

It is because I do not have the 2nd argument in the post which is the body. However your api requests to be in the header not the body?


#14

Hi @handre,

The current issue appears to be with your Bearer token, the call is being rejected because the access token is being rejected. Can you show me the access token inside your call payload, you can find this in the dev console in your browser.

The transaction ID is sent in along with the URL and the access token should be sent in the header:

curl -X POST https://api.moltin.com/v2/orders/:orderId/transactions/:transaction_id/capture \
     -H "Authorization: Bearer XXXX"

#15

HI @drew

It is not my token, it is because when you do a post request, their must be a body argument, it is the second argument. here is my token however:
{expires: 1537614727, identifier: "client_credentials", expires_in: 3600, access_token: "50e7dccdf042300b76ba8ac64737acc2f3492d87", token_type: "Bearer"}

and I post it correctly as the url is correct:
POST https://api.moltin.com/v2/orders/d874864e-b9f8-400e-be5a-b932d31b7953/transactions/0.10369957984933786/capture 401 (Unauthorized)

but I had this error previously when I did post, because I did not insert my body in the POST. However in this case your requests are in the path and not in the body.


#16

Hi @handre sorry for the confusion around this.

Once you have authorized your payment via orders/:order_id/payments

You can then do a GET on orders/c14610c9-900c-4172-95ff-0be932376968/transactions

Which will give a response like:

{
    "data": [
        {
            "id": "f257d8e2-c959-4c71-b3f5-31b2374cf26d",
            "type": "transaction",
            "reference": "manual",
            "gateway": "manual",
            "amount": 20,
            "currency": "USD",
            "transaction-type": "authorize",
            "status": "complete",
            "relationships": {
                "order": {
                    "data": {
                        "type": "order",
                        "id": "c14610c9-900c-4172-95ff-0be932376968"
                    }
                }
            }
        }
    ]
}

You can then take the transaction id and insert it into your URL in the capture call.

Here is an example of the call I am using

curl -X POST \
  https://api.moltin.com/v2/orders/c14610c9-900c-4172-95ff-0be932376968/transactions/f257d8e2-c959-4c71-b3f5-31b2374cf26d/capture \
  -H 'authorization: Bearer XXXX' \
  -H 'content-type: application/json' 

This works in my case and returns a 200 OK http response

The issue with your call looks like there is a problem with your Authentication token, perhaps it is not being refreshed or an incorrect value is being inserted. If you note in my above call there are no body values and the required ids are submitted in the URL.

Hope this helps

Drew


#17

Hi @drew

Thank you, I got confused because previously you mentioned that the transactionId must be self generated.

But everything is working now.
Thank you