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

I can't get accessToken when create new customer #564

Closed mvayak closed 5 years ago

mvayak commented 6 years ago
public Storefront.MutationQuery customerCreateQuery(String email, String pass, String fName, String lName) {
    return Storefront.mutation(mutation -> mutation
            .customerCreate(inputForRegistration(fName, lName, email, pass), query -> query
                    .customer(customer -> customer
                            .id()
                            .email()
                            .firstName()
                            .lastName()
                    )
                    .userErrors(userError -> userError
                            .field()
                            .message()
                    )
            )

    );
}

I'm using

implementation 'com.shopify.mobilebuysdk:buy3:3.2.4'

gradle and I have tried to get access token using above query But I didn't get.

urvidparmar commented 6 years ago

please try this code

  Storefront.CustomerCreateInput customer = new Storefront.CustomerCreateInput(etRegisterEmail.getText().toString(), etRegisterPassword.getText().toString())
                .setFirstName(etFirstName.getText().toString())
                .setLastName(etLastName.getText().toString())
                .setPhone(etMobileNo.getText().toString())
                .setAcceptsMarketing(true);

        Storefront.MutationQuery query = Storefront.mutation(rootQuery -> rootQuery
                .customerCreate(customer, createCustomer -> createCustomer
                        .customer(customerQuery -> customerQuery
                                .firstName()
                                .id()
                                .email()
                                .lastName()
                                .phone()
                        )
                        .userErrors(userErrorQuery -> userErrorQuery
                                .field()
                                .message()
                        )
                )
        );
        graphClient.mutateGraph(query).enqueue(new GraphCall.Callback<Storefront.Mutation>() {
            @Override
            public void onResponse(@NonNull GraphResponse<Storefront.Mutation> response) {
                if (!response.data().getCustomerCreate().getUserErrors().isEmpty()) {
                    for (Storefront.UserError error : response.data().getCustomerCreate().getUserErrors()) {
                        Log.e("TAG", "error" + error.getMessage());

                    }

                } else {
                    Storefront.Customer customer = response.data().getCustomerCreate().getCustomer();
                    Log.e("TAG", "customer " + response.data());
                    Log.e("TAG", "customer " + customer.getId());
                    Log.e("TAG", "customer " + customer.getFirstName());
                    Log.e("TAG", "customer " + customer.getLastName());
                    Log.e("TAG", "customer " + customer.getPhone());
                    Log.e("TAG", "customer " + customer.getEmail());

                }
            }

            @Override
            public void onFailure(@NonNull GraphError error) {
                Log.e("TAG", "customer" + error.getMessage());
            }
        });
mvayak commented 6 years ago

I know about that but my issue is How can I get access token when a new customer is created. Because there is no any parameter for the access token. And SDK new version mention

Return access token for new created customer

GujaratiMonali commented 6 years ago

Not return any access token for creating new customer. please refer mobile buy sdk android-->Creating a customer.

https://github.com/Shopify/mobile-buy-sdk-android#creating-a-customer-

any query than please ask me.

mvayak commented 6 years ago

https://github.com/Shopify/mobile-buy-sdk-android#creating-a-customer-

I know but latest version SDK version provides Return access token for new created customer. Please see it.

GujaratiMonali commented 6 years ago

@mvayak I think both url same than not clear your issues. Mobile buy sdk android clearly define this statement . Keep in mind that this mutation returns a Storefront.Customer object,

not an access token

After a successful mutation, the customer will still be required to log in using their credentials.

mvayak commented 5 years ago

We can get access token while we call registration GraphQL API to see below method. We can call only one API and register the user with access token. we no need to call one API for registration and another for access token.

 fun registrationGraphQuery(email: String, password: String, fName: String, lName: String): Storefront.MutationQuery {
    return Storefront.mutation { mutation ->
        mutation
                .customerCreate(inputForRegistration(fName, lName, email, password)) { query ->
                    query
                            .customer { customer ->
                                customer
                                        .id()
                                        .email()
                                        .firstName()
                                        .lastName()
                            }
                            .userErrors { userErrors -> userErrors
                                        .field()
                                        .message()
                            }
                }
                .customerAccessTokenCreate(inputForLogin(email, password)) { query ->
                    query
                            .customerAccessToken { customerAccessToken ->
                                customerAccessToken
                                        .accessToken()
                                        .expiresAt()
                            }
                            .customerUserErrors { userError -> userError.message().field() }
                }
    }
}