Shopify / mobile-buy-sdk-android

Shopify’s Mobile Buy SDK makes it simple to sell physical products inside your mobile app. With a few lines of code, you can connect your app with the Shopify platform and let your users buy your products using their credit card.
MIT License
214 stars 137 forks source link

Getting issue in Web Checkout's Polling result method #658

Closed rushabh13 closed 4 years ago

rushabh13 commented 4 years ago

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 have faced 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:

rushabh13 commented 4 years ago

Hello All, Found the solution,

Point 1,

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. It will solve your problem.

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()
            }
    }
}
Okiring commented 4 years ago

i was getting the same errors,. tried using your method..but i cant get my retry handler to work,,it only works if i use it like -> RetryHandler.exponentialBackoff(500, TimeUnit.MILLISECONDS, 1.2f) .whenResponse(

                            response ->  ((Storefront.CheckOut) ((GraphResponse<Storefront.QueryRoot>) response).data().getNode()).getReady() == false)

                    .maxCount(50)
                    .build()

But when use it like -> RetryHandler.exponentialBackoff(500, TimeUnit.MILLISECONDS, 1.2f) .whenResponse(

                            response ->  ((Storefront.Payment) ((GraphResponse<Storefront.QueryRoot>) response).data().getNode()).getReady() == false)

                    .maxCount(50)
                    .build()

it just fails to reschedule e request. How did u get past this issue...i removed the default cache policy from the client and during request i set it to Network Only. The polling only works on the shipping methods. but is failing upon polling for checkout completion.

monali2610 commented 4 years ago

I was getting the same errors.

Okiring commented 4 years ago

i managed to solve the issue .....in the retry handler,check if order == null..keep polling untill order is not equal to null. i did that and tested with a web checkout..after making payment for a product.. i got response with the order-id...shopifyz documentation is not updated at all.....

asadwaheed1 commented 3 years ago

i managed to solve the issue .....in the retry handler,check if order == null..keep polling untill order is not equal to null. i did that and tested with a web checkout..after making payment for a product.. i got response with the order-id...shopifyz documentation is not updated at all.....

Thank you I am able to fix same issue using your answer