Re: Order API - determine if purchased with credit card, regardess of payment gateway

Order API - determine if purchased with credit card, regardess of payment gateway

dylanpierce
Shopify Partner
279 13 121

Via the Order Admin REST API or GraphQL API, is it possible to see the payment method for a given order regardless of the payment gateway?

 

I’m trying to detect if a given order was paid with a credit card, and ignore all other payment method types, like cash, check, ACH, etc.

Founder of Real ID - Verify your customer's real IDs easily & securely with modern A.I.

Want to see it in action? Check out our demo store.

Replies 3 (3)

shuleGoing
Shopify Partner
32 1 5

Hi 

I see the transaction resource returns the credit card company https://shopify.dev/api/admin-rest/2022-10/resources/transaction#resource-object
What I have not tested here is what is returned if it is credit card but a different "method" such as payment terms via Shopify Payments. 

First Light - Shopify development agency
Specialists in Shopify custom app development and integrations
shule@firstlight.dev
dylanpierce
Shopify Partner
279 13 121

Thanks @shuleGoing , this was my go to method for about a year, but now the order REST resource no longer includes payment details as of `2023-04` which is the new minimum Shopify Admin API version.

I'm reviewing the order transactions but there doesn't seem to be an equivalent field to detect credit card payments:

https://shopify.dev/docs/api/admin-graphql/2023-04/objects/OrderTransaction

Founder of Real ID - Verify your customer's real IDs easily & securely with modern A.I.

Want to see it in action? Check out our demo store.

dylanpierce
Shopify Partner
279 13 121

I believe I've found a solution.

The `PaymentDetails` on an `OrderTransaction` does provide a `company` field.

This might be the equivalent of the old REST `order.payment_details.company_name`, at least I'm hoping so.

I can see that an order paid with the Bogus Gateway will have this path filled, but unfortunately it looks like Development Stores no longer Cash on Delivery (COD) as a valid payment, so I can't test further.

But for anyone else finding this thread, here's the query I'm trying to detect a credit card payment with:

```

query getOrderPaymentDetails($id: ID!) {
  order(id: $id) {
      transactions(first: 5) {
         paymentDetails {
           ... on CardPaymentDetails {
           company
         }
       }
    }
}


```

The hope is that testing for the presence of the `company` field like with `order.transactions.some(txn => txn.paymentDetails?.company)`  will detect a credit card payment instead of a cash, PayPal, etc payment.

Founder of Real ID - Verify your customer's real IDs easily & securely with modern A.I.

Want to see it in action? Check out our demo store.