public void SetEmailAddress(string email, CompletionCallback callback) { MutationQuery query = new MutationQuery(); DefaultQueries.checkout.EmailUpdate(query, CurrentCheckout.id(), email); Client.Mutation(query, (Mutation response, ShopifyError error) => { if (error != null) { callback(error); } else { if (UpdateState(response.checkoutEmailUpdateV2().checkout(), response.checkoutEmailUpdateV2().userErrors())) { if (CurrentCheckout.ready()) { callback(null); } else { PollCheckoutAndUpdate(PollCheckoutReady, callback); } } else { HandleUserError(callback); } } }); }
public void SetShippingLine(string shippingRateHandle, CompletionCallback callback) { MutationQuery query = new MutationQuery(); DefaultQueries.checkout.ShippingLineUpdate(query, CurrentCheckout.id(), shippingRateHandle); Client.Mutation(query, (Mutation response, ShopifyError error) => { if (error != null) { callback(error); return; } if (UpdateState(response.checkoutShippingLineUpdate().checkout(), response.checkoutShippingLineUpdate().userErrors())) { if (CurrentCheckout.ready()) { callback(null); } else { PollCheckoutAndUpdate(PollCheckoutReady, callback); } } else { HandleUserError(callback); } }); }
private void CreateRemoteCheckoutFromLocalState(CompletionCallback callback) { MutationQuery query = new MutationQuery(); List <CheckoutLineItemInput> newLineItemInput = CartLineItems.ConvertToCheckoutLineItemInput(LineItems.All()); DefaultQueries.checkout.Create(query, newLineItemInput); Client.Mutation(query, (Mutation response, ShopifyError error) => { if (error != null) { callback(error); return; } if (UpdateState(response.checkoutCreate().checkout(), response.checkoutCreate().userErrors())) { if (CurrentCheckout.ready()) { callback(null); } else { PollCheckoutAndUpdate(PollCheckoutReady, callback); } } else { HandleUserError(callback); } }); }
/// <summary> /// Allows you to build and send custom GraphQL mutation queries to the Storefront API. /// </summary> /// <param name="buildQuery">delegate that will build a query starting at <see ref="QueryRootQuery">MutationQuery </see></param> /// <param name="callback">callback which will receive a response</param> /// \code /// // Example that creates a new customer on a store /// ShopifyBuy.Client().Mutation( /// buildQuery: (mutation) => { mutation /// .customerCreate( /// buildQuery: (cc) => { cc /// .userErrors( /// buildQuery: (ue) => { ue /// .field() /// .message(); /// } /// ); /// }, /// input: new CustomerCreateInput( /// email: "*****@*****.**", /// password: "******" /// ) /// ); /// }, /// callback: (data, error) => { /// if (error != null) { /// Debug.Log("There was an error: " + error.Reason); /// } else { /// List<UserError> userErrors = data.customerCreate().userErrors(); /// /// if (userErrors != null) { /// foreach(UserError error in userErrors) { /// // field which may have a user error /// Debug.Log(error.field()); /// // error message for the field which had an error /// Debug.Log(error.message()); /// } /// } else { /// Debug.Log("No user errors the customer was created"); /// } /// } /// } /// ); /// \endcode public void Mutation(MutationDelegate buildQuery, MutationRootHandler callback) { MutationQuery query = new MutationQuery(); buildQuery(query); Mutation(query, callback); }
public void TestShippingLineUpdate() { MutationQuery query = new MutationQuery(); string checkoutId = "an-id"; DefaultQueries.checkout.ShippingLineUpdate(query, checkoutId, "handle"); Assert.AreEqual( "mutation{checkoutShippingLineUpdate (checkoutId:\"an-id\",shippingRateHandle:\"handle\"){checkout {id webUrl currencyCode requiresShipping subtotalPrice totalTax totalPrice ready shippingLine {handle title price }}userErrors {field message }}}", query.ToString() ); }
public void TestEmailUpdate() { MutationQuery query = new MutationQuery(); string checkoutId = "an-id"; DefaultQueries.checkout.EmailUpdate(query, checkoutId, "*****@*****.**"); Assert.AreEqual( "mutation{checkoutEmailUpdateV2 (checkoutId:\"an-id\",email:\"[email protected]\"){checkout {email }userErrors {field message }}}", query.ToString() ); }
public void TestCheckoutCreate() { MutationQuery query = new MutationQuery(); List <CheckoutLineItemInput> lineItems = new List <CheckoutLineItemInput>(); DefaultQueries.checkout.Create(query, lineItems); Assert.AreEqual( "mutation{checkoutCreate (input:{lineItems:[],allowPartialAddresses:true}){checkout {id webUrl currencyCode requiresShipping subtotalPrice totalTax totalPrice ready lineItems (first:250){edges {node {id variant {id }}cursor }pageInfo {hasNextPage }}}userErrors {field message }}}", query.ToString() ); }
public void TestCheckoutLineItemsRemove() { MutationQuery query = new MutationQuery(); string checkoutId = "an-id"; List <string> lineItemIds = new List <string>(); DefaultQueries.checkout.LineItemsRemove(query, checkoutId, lineItemIds); Assert.AreEqual( "mutation{checkoutLineItemsRemove (checkoutId:\"an-id\",lineItemIds:[]){userErrors {field message }}}", query.ToString() ); }
public void TestCheckoutLineItemsAdd() { MutationQuery query = new MutationQuery(); string checkoutId = "an-id"; List <CheckoutLineItemInput> lineItems = new List <CheckoutLineItemInput>(); DefaultQueries.checkout.LineItemsAdd(query, checkoutId, lineItems); Assert.AreEqual( "mutation{checkoutLineItemsAdd (lineItems:[],checkoutId:\"an-id\"){checkout {id webUrl currencyCode requiresShipping subtotalPrice totalTax totalPrice ready lineItems (first:250){edges {node {id variant {id }}cursor }pageInfo {hasNextPage }}}userErrors {field message }}}", query.ToString() ); }
public void LineItemsRemove(MutationQuery query, string checkoutId, List <string> lineItemIds) { query.checkoutLineItemsRemove( buildQuery: lineItemRemove => lineItemRemove .userErrors(userErrors => userErrors .field() .message() ), checkoutId: checkoutId, lineItemIds: lineItemIds ); }
public void ShippingAddressUpdate(MutationQuery query, string checkoutId, MailingAddressInput shippingAddress) { query.checkoutShippingAddressUpdate( buildQuery: shippingAddressUpdate => shippingAddressUpdate .checkout(checkout => Checkout(checkout)) .userErrors(userErrors => userErrors .field() .message() ), shippingAddress: shippingAddress, checkoutId: checkoutId ); }
public void EmailUpdate(MutationQuery query, string checkoutId, String email) { query.checkoutEmailUpdate( buildQuery: emailUpdate => emailUpdate .checkout(checkout => checkout .email()) .userErrors(userErrors => userErrors .field() .message() ), checkoutId: checkoutId, email: email ); }
public void TestShippingAddressUpdate() { MutationQuery query = new MutationQuery(); string checkoutId = "an-id"; var addressInput = new MailingAddressInput("123 Test Street", "456", "Toronto", "Shopify", "Canada", "First", "Last", "1234567890", "Ontario", "A1B2C3"); DefaultQueries.checkout.ShippingAddressUpdate(query, checkoutId, addressInput); Assert.AreEqual( "mutation{checkoutShippingAddressUpdateV2 (shippingAddress:{address1:\"123 Test Street\",address2:\"456\",city:\"Toronto\",company:\"Shopify\",country:\"Canada\",firstName:\"First\",lastName:\"Last\",phone:\"1234567890\",province:\"Ontario\",zip:\"A1B2C3\"},checkoutId:\"an-id\"){checkout {id webUrl currencyCode requiresShipping subtotalPrice totalTax totalPrice ready }userErrors {field message }}}", query.ToString() ); }
public void ShippingLineUpdate(MutationQuery query, string checkoutId, String shippingRateHandle) { query.checkoutShippingLineUpdate( buildQuery: emailUpdate => emailUpdate .checkout(checkout => Checkout(checkout) .shippingLine(shippingLine => ShippingRate(shippingLine))) .userErrors(userErrors => userErrors .field() .message() ), checkoutId: checkoutId, shippingRateHandle: shippingRateHandle ); }
public void CheckoutCompleteWithTokenizedPayment(MutationQuery query, string checkoutId, TokenizedPaymentInput tokenizedPaymentInput) { query.checkoutCompleteWithTokenizedPayment( buildQuery: checkoutCompleteWithTokenizedPayment => checkoutCompleteWithTokenizedPayment .checkout(checkout => Checkout(checkout)) .payment(payment => Payment(payment)) .userErrors(userErrors => userErrors .field() .message() ), checkoutId: checkoutId, payment: tokenizedPaymentInput ); }
public void LineItemsAdd(MutationQuery query, string checkoutId, List <CheckoutLineItemInput> lineItems) { query.checkoutLineItemsAdd( buildQuery: lineItemAdd => lineItemAdd .checkout(checkout => { Checkout(checkout); CheckoutLineItems(checkout); }) .userErrors(userErrors => userErrors .field() .message() ), checkoutId: checkoutId, lineItems: lineItems ); }
public void Create(MutationQuery query, List <CheckoutLineItemInput> lineItems) { query.checkoutCreate( buildQuery: checkoutCreate => checkoutCreate .checkout(checkout => { Checkout(checkout); CheckoutLineItems(checkout); }) .userErrors(userErrors => userErrors .field() .message() ), input: new CheckoutCreateInput( allowPartialAddresses: true, lineItems: lineItems ) ); }
public void TestCheckoutCompleteWithTokenizedPayment() { MutationQuery query = new MutationQuery(); string checkoutId = "an-id"; var billingAddress = new MailingAddressInput("123 Test Street", "456", "Toronto", "Shopify", "Canada", "First", "Last", "1234567890", "Ontario", "A1B2C3"); var tokenizedPaymentInput = new TokenizedPaymentInput( amount: new decimal(1), idempotencyKey: "unique_id", billingAddress: billingAddress, paymentData: "some_utf8_data_string", type: "apple_pay" ); DefaultQueries.checkout.CheckoutCompleteWithTokenizedPayment(query, checkoutId, tokenizedPaymentInput); Assert.AreEqual( "mutation{checkoutCompleteWithTokenizedPayment (checkoutId:\"an-id\",payment:{amount:1,idempotencyKey:\"unique_id\",billingAddress:{address1:\"123 Test Street\",address2:\"456\",city:\"Toronto\",company:\"Shopify\",country:\"Canada\",firstName:\"First\",lastName:\"Last\",phone:\"1234567890\",province:\"Ontario\",zip:\"A1B2C3\"},type:\"apple_pay\",paymentData:\"some_utf8_data_string\"}){checkout {id webUrl currencyCode requiresShipping subtotalPrice totalTax totalPrice ready }payment {checkout {id webUrl currencyCode requiresShipping subtotalPrice totalTax totalPrice ready completedAt }errorMessage id ready }userErrors {field message }}}", query.ToString() ); }
private void UpdateRemoteCheckoutFromLocalState(CompletionCallback callback) { MutationQuery query = new MutationQuery(); // remove all line items them add them List <string> lineItemsToRemove = CartLineItems.ConvertToLineItemIds(LineItems.All()); lineItemsToRemove.AddRange(DeletedLineItems); List <CheckoutLineItemInput> lineItemsToAdd = CartLineItems.ConvertToCheckoutLineItemInput(LineItems.All()); DefaultQueries.checkout.LineItemsRemove(query, CurrentCheckout.id(), lineItemsToRemove); DefaultQueries.checkout.LineItemsAdd(query, CurrentCheckout.id(), lineItemsToAdd); Client.Mutation(query, (Mutation response, ShopifyError error) => { if (error != null) { callback(error); return; } DeletedLineItems.Clear(); if (UpdateState(response.checkoutLineItemsAdd().checkout(), response.checkoutLineItemsAdd().userErrors())) { if (CurrentCheckout.ready()) { callback(null); } else { PollCheckoutAndUpdate(PollCheckoutReady, callback); } } else { HandleUserError(callback); } }); }
public void MutationRootBuildsQuery() { MutationQuery query = new MutationQuery(); query .customerAccessTokenCreate(r => r .customerAccessToken(a => a .accessToken() ), input: new CustomerAccessTokenCreateInput(email: "*****@*****.**", password: "******") ); Assert.AreEqual( "mutation{customerAccessTokenCreate (input:{email:\"[email protected]\",password:\"123456\"}){customerAccessToken {accessToken }}}", query.ToString() ); // check that ToString does not mutate Assert.AreEqual( "mutation{customerAccessTokenCreate (input:{email:\"[email protected]\",password:\"123456\"}){customerAccessToken {accessToken }}}", query.ToString() ); }
/// <summary> /// Sends GraphQL mutations to a GraphQL endpoint. /// </summary> /// <param name="query">mutation to be sent to GraphQL endpoint</param> /// <param name="callback">callback that receives the mutation response</param> public void Mutation(MutationQuery query, MutationResponseHandler callback) { #if SHOPIFY_VERBOSE_DEBUG Console.WriteLine("Sending Mutation: " + query.ToString() + "\n"); #endif Loader.Load(query.ToString(), (string response, string error) => { #if SHOPIFY_VERBOSE_DEBUG Console.WriteLine("Response: " + response + "\n"); Console.WriteLine("Error: " + error + "\n"); #endif if (error != null) { callback(new MutationResponse(error)); } else { callback(new MutationResponse(GetJSON(response))); } }); }
public void SetFinalCheckoutFields(string email, ShippingFields?shippingFields, CompletionCallback callback) { MutationQuery query = new MutationQuery(); DefaultQueries.checkout.EmailUpdate(query, CurrentCheckout.id(), email); if (shippingFields.HasValue) { DefaultQueries.checkout.ShippingAddressUpdate(query, CurrentCheckout.id(), shippingFields.Value.ShippingAddress); DefaultQueries.checkout.ShippingLineUpdate(query, CurrentCheckout.id(), shippingFields.Value.ShippingIdentifier); } Client.Mutation(query, (Mutation response, ShopifyError error) => { if (error != null) { callback(error); } else { var userErrors = response.checkoutShippingAddressUpdateV2().userErrors(); if (shippingFields.HasValue) { userErrors.AddRange(response.checkoutShippingLineUpdate().userErrors()); userErrors.AddRange(response.checkoutEmailUpdateV2().userErrors()); } if (UpdateState(response.checkoutEmailUpdateV2().checkout(), userErrors)) { PollCheckoutAndUpdate(PollCheckoutReady, callback); } else { HandleUserError(callback); } } }); }
private void SetupCustomerAccessToken() { MutationQuery mutation = new MutationQuery(); mutation.customerAccessTokenCreate((a) => a .customerAccessToken(at => at .accessToken() ), input: new CustomerAccessTokenCreateInput("*****@*****.**", "password") ); AddResponse( mutation, @"{ ""data"": { ""customerAccessTokenCreate"": { ""customerAccessToken"": { ""accessToken"": ""i am a token"" } } } }" ); }
public void TestCheckoutCompleteWithTokenizedPaymentV2() { MutationQuery query = new MutationQuery(); string checkoutId = "an-id"; var billingAddress = new MailingAddressInput("123 Test Street", "456", "Toronto", "Shopify", "Canada", "First", "Last", "1234567890", "Ontario", "A1B2C3"); var paymentAmount = new MoneyInput(new decimal(1), CurrencyCode.CAD); var tokenizedPaymentInputV2 = new TokenizedPaymentInputV2( paymentAmount: paymentAmount, idempotencyKey: "unique_id", billingAddress: billingAddress, paymentData: "some_utf8_data_string", type: "apple_pay" ); var expectedResult = "mutation{checkoutCompleteWithTokenizedPaymentV2 (checkoutId:\"an-id\",payment:{paymentAmount:{amount:1,currencyCode:CAD},idempotencyKey:\"unique_id\",billingAddress:{address1:\"123 Test Street\",address2:\"456\",city:\"Toronto\",company:\"Shopify\",country:\"Canada\",firstName:\"First\",lastName:\"Last\",phone:\"1234567890\",province:\"Ontario\",zip:\"A1B2C3\"},paymentData:\"some_utf8_data_string\",type:\"apple_pay\"}){checkout {id webUrl currencyCode requiresShipping subtotalPriceV2 {amount currencyCode }totalTaxV2 {amount currencyCode }totalPriceV2 {amount currencyCode }ready }payment {checkout {id webUrl currencyCode requiresShipping subtotalPriceV2 {amount currencyCode }totalTaxV2 {amount currencyCode }totalPriceV2 {amount currencyCode }ready completedAt }errorMessage id ready }checkoutUserErrors {code field message }}}"; DefaultQueries.checkout.CheckoutCompleteWithTokenizedPaymentV2(query, checkoutId, tokenizedPaymentInputV2); Assert.AreEqual( expectedResult, query.ToString(), string.Format("Unexpected mutation response.\n Expected response: {0}\n Actual response: {1}", expectedResult, query) ); }
public void SetShippingAddress(MailingAddressInput mailingAddressInput, CompletionCallback callback) { MutationQuery query = new MutationQuery(); DefaultQueries.checkout.ShippingAddressUpdate(query, CurrentCheckout.id(), mailingAddressInput); Client.Mutation(query, (Mutation response, ShopifyError error) => { if (error != null) { callback(error); } else { if (UpdateState(response.checkoutShippingAddressUpdateV2().checkout(), response.checkoutShippingAddressUpdateV2().userErrors())) { PollCheckoutAndUpdate(PollCheckoutAvailableShippingRatesReady, callback); } else { HandleUserError(callback); } } }); }
public MutationSchema() { Query = new MutationQuery(); Mutation = new MutationChange(); }
protected void AddResponse(MutationQuery query, string response) { AddResponse(query.ToString(), response); }
/// <summary> /// Allows you to send custom prebuilt GraphQL mutation queries to the Storefront API. /// </summary> /// <param name="query">a query to be sent to the Storefront API</param> /// <param name="callback">callback which will receive a response</param> /// \code /// // Example that creates a custom mutation query /// MutationQuery mutation = new MutationQuery(); /// /// mutation.customerCreate( /// buildQuery: (cc) => { cc /// .userErrors( /// buildQuery: (ue) => { ue /// .field() /// .message(); /// } /// ); /// }, /// input: new CustomerCreateInput( /// email: "*****@*****.**", /// password: "******" /// ) /// ); /// /// ShopifyBuy.Client().Mutation( /// query: mutation, /// callback: (data, error) => { /// if (error != null) { /// Debug.Log("There was an error: " + error.Reason); /// } else { /// List<UserError> userErrors = data.customerCreate().userErrors(); /// /// if (userErrors != null) { /// foreach(UserError error in userErrors) { /// // field which may have a user error /// Debug.Log(error.field()); /// // error message for the field which had an error /// Debug.Log(error.message()); /// } /// } else { /// Debug.Log("No user errors the customer was created"); /// } /// } /// } /// ); /// \endcode public void Mutation(MutationQuery query, MutationRootHandler callback) { Loader.Mutation(query, (response) => { callback(response.data, (ShopifyError)response); }); }
public void CheckoutWithTokenizedPaymentV2(TokenizedPaymentInputV2 tokenizedPaymentInputV2, CompletionCallback callback) { Action <Payment> pollPayment = (payment) => { PollPaymentReady(payment.id(), (Payment newPayment, ShopifyError error) => { if (error != null) { callback(error); } else { if (UpdateState(payment.checkout())) { callback(null); } else { HandleUserError(callback); } } }); }; Action checkoutWithTokenizedPaymentV2 = () => { MutationQuery query = new MutationQuery(); DefaultQueries.checkout.CheckoutCompleteWithTokenizedPaymentV2(query, CurrentCheckout.id(), tokenizedPaymentInputV2); Client.Mutation(query, (Mutation response, ShopifyError error) => { if (error != null) { callback(error); return; } else { var responseNode = response.checkoutCompleteWithTokenizedPaymentV2(); var payment = responseNode.payment(); if (UpdateState(responseNode.checkout(), responseNode.userErrors())) { if (payment.ready()) { callback(null); } else { pollPayment(payment); } } else { HandleUserError(callback); } } }); }; // Ensure we can checkout first if (CurrentCheckout.ready()) { checkoutWithTokenizedPaymentV2(); } else { PollCheckoutReady((Checkout checkout, ShopifyError error) => { if (error != null) { callback(error); } else { checkoutWithTokenizedPaymentV2(); } }); } }