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 136 forks source link

Polling Checkout no errors #515

Closed aShaforostov closed 6 years ago

aShaforostov commented 6 years ago

When i make "Polling for checkout completion" after "checkoutCompleteWithCreditCard", with not valid credit card, I'm not get any errors. While polling in progress, I go to Abandoned checkouts in my store, in browser, and see that payment with error "Your card was declined.", but this error not exist in polling response

Hafros commented 6 years ago

Make Pull Request for update docs for this issue

amanzan commented 6 years ago

@Hafros I get "java.lang.ClassCastException: com.shopify.buy3.Storefront$Checkout cannot be cast to com.shopify.buy3.Storefront$Payment" with the changes on your Pull Request

Hafros commented 6 years ago

@amanzan Attach please your code

It's my working void

public void pollingForCheckoutCompletion(String checkout_id, String payment_id, final CheckoutRequestComplete completeHandler, final CheckoutRequestFail failHandler){

            //ID checkoutId = new ID(checkout_id);

            ID paymentId = new ID(payment_id);

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

            this.client().queryGraph(query).enqueue(
                    new GraphCall.Callback<Storefront.QueryRoot>() {
                        @Override public void onResponse(@NonNull GraphResponse<Storefront.QueryRoot> response) {
                            Storefront.Payment payment = (Storefront.Payment) response.data().getNode();

                            if (payment.getErrorMessage() == null || payment.getErrorMessage().isEmpty()){
                                completeHandler.callback(payment.getCheckout());
                            }
                            else{

                                failHandler.callback(payment.getErrorMessage());

                            }

                        }

                        @Override public void onFailure(@NonNull GraphError error) {
                            failHandler.callback(error.getLocalizedMessage());
                        }
                    },
                    null,
                    RetryHandler.exponentialBackoff(500, TimeUnit.MILLISECONDS, 1.2f)
                            .whenResponse(
                                    response -> ((Storefront.Payment) ((GraphResponse<Storefront.QueryRoot>) response).data().getNode()).getReady() == false
                            )
                            .maxCount(12)
                            .build()
            );

        }
amanzan commented 6 years ago

I might had made a mistake before, now my code is like yours. But now I get "com.shopify.buy3.GraphError: Failed to reschedule GraphQL query execution". How do you create your GraphClient?

Hafros commented 6 years ago

@amanzan

private GraphClient client(){

        HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
        logging.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient client = new OkHttpClient.Builder()
                .addInterceptor(logging)
                .build();

        return GraphClient.builder(context)
                .shopDomain(BuildConfig.SHOP_DOMAIN)
                .accessToken(BuildConfig.API_KEY)
                .httpClient(client)
                //.httpCache(new File(context.getApplicationContext().getCacheDir(), "/http"), 10 * 1024 * 1024) // 10mb for http cache
               // .defaultHttpCachePolicy(HttpCachePolicy.NETWORK_ONLY), //.expireAfter(5, TimeUnit.MINUTES)) // cached response valid by default for 5 minutes
                .build();

    }
amanzan commented 6 years ago

Still same error, "com.shopify.buy3.GraphError: Failed to reschedule GraphQL query execution" I couldn't get RetryHandler to work for some reason, so I gave up and created my own. Thanks anyway, I still can use your code for checking payment errors :)

dudadayan commented 6 years ago

I'm using your polling code right after checkoutCompleteWithCreditCard and the payment object never get ready even though i can see in the admin web console the confirmed order. any suggestions?

aShaforostov commented 6 years ago

@dudadayan Have you tried to increase the maxCount?

dudadayan commented 6 years ago

@aShaforostov Yes, with no success

aShaforostov commented 6 years ago

@dudadayan Check your "Payment authorization" in shop settings

Settings -> Payment providers

In my case there is an "Automatically capture payment for orders."

dudadayan commented 6 years ago

@aShaforostov Thanks, I changed it to capture payments, but still, it didn't work

aShaforostov commented 6 years ago

@dudadayan What is payment gateway your using? In my case is Stripe

dudadayan commented 6 years ago

@aShaforostov I'm using "Network Merchants (NMI)" as my gateway (in test mode). I don't think the problem is with them because I can see all the orders i made as confirmed in my shopify admin panel.

aShaforostov commented 6 years ago

@dudadayan Most likely this is because of the test mode, try to disconnect it and try to make a real transaction

sav007 commented 6 years ago

@aShaforostov is this issue still exist?

aShaforostov commented 6 years ago

@sav007 I'm with @Hafros found a solution. Problem in you docs. Pull request was made

sav007 commented 6 years ago

Thx will merge it!!

sav007 commented 6 years ago

addressed in docs: https://github.com/Shopify/mobile-buy-sdk-android/pull/516

ranamrameez commented 4 years ago

Still same error, "com.shopify.buy3.GraphError: Failed to reschedule GraphQL query execution" I couldn't get RetryHandler to work for some reason, so I gave up and created my own. Thanks anyway, I still can use your code for checking payment errors :)

@amanzan can u please share your code

ShivaniApporio commented 4 years ago

@Hafros how i can resolve this issue ""com.shopify.buy3.GraphError: Failed to reschedule GraphQL query execution"

asadwaheed1 commented 4 years ago

I am also facing this issue "com.shopify.buy3.GraphError: Failed to reschedule GraphQL query execution"

asadwaheed1 commented 4 years ago

If I remove rescheduling code I get "java.lang.ClassCastException: com.shopify.buy3.Storefront$Checkout cannot be cast to com.shopify.buy3.Storefront$Payment"