Rushabh Shah
Rushabh Shah

Reputation: 371

Shopify Web Checkout Issue

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:

Upvotes: 1

Views: 564

Answers (1)

Rushabh Shah
Rushabh Shah

Reputation: 371

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()
            }
    }
}

Upvotes: 1

Related Questions