Shopify Web Checkout Issue

544 Views Asked by At

I am doing WebCheckout. After that, I am getting a callback of that Checkout callback.

I have followed the way which has been written here.

GraphClient client = ...;
ID paymentId = ...;

Storefront.QueryRootQuery query = Storefront.query(rootQuery -> rootQuery
    .node(paymentId, nodeQuery -> nodeQuery
        .onPayment(paymentQuery -> paymentQuery
        .checkout(checkoutQuery -> checkoutQuery
                    .ready()
            .order(orderQuery -> orderQuery
            .processedAt()
            .orderNumber()
            .totalPrice()))
        .errorMessage()
        .ready()
        )
    )
);

======================================================================

I am facing the following issues:

1. ID paymentId = ...;

It shouldn't be paymentId, It is checkoutId while will be received in response of this request.

2. Not getting null value in the response of below code:

Storefront.QueryRootQuery query = Storefront.query(rootQuery -> rootQuery
    .node(paymentId, nodeQuery -> nodeQuery
        .onPayment(paymentQuery -> paymentQuery
        .checkout(checkoutQuery -> checkoutQuery
            .order(orderQuery -> orderQuery
            .processedAt()
            .orderNumber()
            .totalPrice()))
        .errorMessage()
        .ready()
        )
    )
);

- 2.1 If I removed the below line than I can able to get some data:

.onPayment(paymentQuery -> paymentQuery

So, code will be look like this :

.node(paymentId) { nodeQuery: NodeQuery ->
    nodeQuery.onCheckout { checkoutQuery: CheckoutQuery ->
        checkoutQuery
            .createdAt()
            .updatedAt()
            .completedAt()
            .email()
            .ready()
            .order {
                it.orderNumber()
            }
    }
}

In above code, I am always getting ready=true (Whether I have purchased the product or not). The ready field is using inside the retryHandler function.

RetryHandler.exponentialBackoff(500, TimeUnit.MILLISECONDS, 1.2f)
.whenResponse(
      response -> ((Storefront.Payment) ((GraphResponse<Storefront.QueryRoot>) response).data().getNode()).getReady() == false
    )
    .maxCount(12)
    .build()

- 2.2, I am getting order=null. I need orderNumber to display, so how can I get that?

==================================================================

Expected behavior:

  • In Point 1, It might be some typing mistake, instead of paymentId, it must display checkoutId. As it is confusing to the developer.
  • In Point 2, It must return the needed data.
  • In Point 2.1, The ready field must be changed when the order is successfully placed.
  • In Point 2.2, The order field must not be null.
1

There are 1 best solutions below

1
On BEST ANSWER

Found the solution,

Point 1,

  • It is checkoutId not paymentId

Point 2,

NOTE: Please make a note that, for getting updated result, you have to remove the defaultCachePolicy from the GraphClient object where we are setting up our shop to Shopify.

Now, while Polling for checkout completion, pass HTTPCachePolicy as

HttpCachePolicy.Default.NETWORK_ONLY

And the query will be as follows,

rootQuery.node(paymentId) { nodeQuery: NodeQuery ->
    nodeQuery.onCheckout { checkoutQuery: CheckoutQuery ->
        checkoutQuery
            .createdAt()
            .updatedAt()
            .completedAt()
            .email()
            .ready()
            .order {
                it.orderNumber()
            }
    }
}