/// <summary> /// Callback which is invoked when the user confirms the checkout after /// reviewing the confirmation screen. /// </summary> /// <param name="serializedMessage"> /// A <see cref="ShippingMethod"> object represented as a JSON string /// containing the selected shipping method. /// </param> public void OnConfirmCheckout(string serializedMessage) { var checkout = CartState.CurrentCheckout; var message = NativeMessage.CreateFromJSON(serializedMessage); var amount = checkout.totalPrice(); var payment = new NativePayment(message.Content); var tokenizedPaymentInput = new TokenizedPaymentInput( amount: amount, billingAddress: payment.BillingAddress, idempotencyKey: payment.TransactionIdentifier, paymentData: payment.PaymentData, identifier: payment.Identifier, type: "android_pay" ); CartState.SetEmailAddress(payment.Email, (ShopifyError error) => { if (error == null) { PerformCheckout(tokenizedPaymentInput, message); } else { RespondError(message, error); OnFailure(error); } }); }
private void CheckoutWithTokenizedPayment(TokenizedPaymentInput tokenizedPaymentInput, Checkout checkout, ApplePayEventHandlerCompletion callback) { CartState.CheckoutWithTokenizedPayment(tokenizedPaymentInput, (ShopifyError error) => { if (error == null) { callback(null); } else { ApplePayEventResponse response = new ApplePayEventResponse(ApplePayAuthorizationStatus.Failure); // Check to see if this is a recoverable user error if (error.Type == ShopifyError.ErrorType.UserError) { var userErrors = CartState.UserErrors; var status = GetUpdateRequestStatusFromCheckoutUserErrors(userErrors); if (status.AuthorizationStatus != ApplePayAuthorizationStatus.Failure) { var summaryItems = GetSummaryItemsFromCheckout(CartState.CurrentCheckout); response = new ApplePayEventResponse(status.AuthorizationStatus, summaryItems, GetShippingMethods(), status.Errors); } } callback(response); } }); }
public void FetchApplePayCheckoutStatusForToken(string serializedMessage) { var checkout = CartState.CurrentCheckout; var message = NativeMessage.CreateFromJSON(serializedMessage); var amount = checkout.totalPrice(); var payment = new NativePayment(message.Content); var tokenizedPaymentInput = new TokenizedPaymentInput(amount: amount, billingAddress: payment.BillingAddress, idempotencyKey: payment.TransactionIdentifier, paymentData: payment.PaymentData, type: "apple_pay"); Action performCheckout = () => { CheckoutWithTokenizedPayment(tokenizedPaymentInput, checkout, (ApplePayEventResponse errorResponse) => { if (errorResponse == null) { message.Respond((new ApplePayEventResponse(ApplePayAuthorizationStatus.Success)).ToJsonString()); } else { message.Respond(errorResponse.ToJsonString()); } }); }; SetFinalCheckoutFieldsForPayment(payment, checkout, (ApplePayEventResponse errorResponse) => { if (errorResponse == null) { performCheckout(); } else { message.Respond(errorResponse.ToJsonString()); } }); }
/// <summary> /// Updates the cart state by sending the checkout token. /// </summary> /// <param name="tokenizedPaymentInput"> /// A <see cref="TokenizedPaymentInput"> containing all information /// needed to complete the checkout. /// </param> /// <param name="message"> /// A <see cref="NativeMessage"> object to call back to the Android plugin /// when the checkout is successful or failed. /// </param> private void PerformCheckout(TokenizedPaymentInput tokenizedPaymentInput, NativeMessage message) { CartState.CheckoutWithTokenizedPayment(tokenizedPaymentInput, (ShopifyError error) => { if (error == null) { AndroidPayCheckoutResponse.Status status = AndroidPayCheckoutResponse.Status.Success; message.Respond(new AndroidPayCheckoutResponse(status).ToJsonString()); OnSuccess(); } else { AndroidPayCheckoutResponse.Status status = AndroidPayCheckoutResponse.Status.Failure; message.Respond(new AndroidPayCheckoutResponse(status).ToJsonString()); OnFailure(error); } }); }
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() ); }
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 ); }
/// \deprecated Use `checkoutCompleteWithTokenizedPaymentV2` instead /// <summary> /// Completes a checkout with a tokenized payment. /// </summary> /// <param name="checkoutId"> /// The ID of the checkout. /// </param> /// <param name="payment"> /// The info to apply as a tokenized payment. /// </param> public MutationQuery checkoutCompleteWithTokenizedPayment(CheckoutCompleteWithTokenizedPaymentPayloadDelegate buildQuery, string checkoutId, TokenizedPaymentInput payment, string alias = null) { Log.DeprecatedQueryField("Mutation", "checkoutCompleteWithTokenizedPayment", "Use `checkoutCompleteWithTokenizedPaymentV2` instead"); if (alias != null) { ValidationUtils.ValidateAlias(alias); Query.Append("checkoutCompleteWithTokenizedPayment___"); Query.Append(alias); Query.Append(":"); } Query.Append("checkoutCompleteWithTokenizedPayment "); Arguments args = new Arguments(); args.Add("checkoutId", checkoutId); args.Add("payment", payment); Query.Append(args.ToString()); Query.Append("{"); buildQuery(new CheckoutCompleteWithTokenizedPaymentPayloadQuery(Query)); Query.Append("}"); return(this); }