Пример #1
0
        private void RespondToUpdateAddressSuccessForMessage(NativeMessage message)
        {
            var shippingMethods = GetShippingMethods();

            if (shippingMethods.Count > 0)
            {
                // Set the first shipping method as the default
                CartState.SetShippingLine(shippingMethods[0].Identifier, (ShopifyError error) => {
                    if (error == null)
                    {
                        var summaryItems = GetSummaryItemsFromCheckout(CartState.CurrentCheckout);
                        message.Respond(new ApplePayEventResponse(ApplePayAuthorizationStatus.Success, summaryItems, shippingMethods).ToJsonString());
                    }
                    else
                    {
                        message.Respond(new ApplePayEventResponse(ApplePayAuthorizationStatus.Failure).ToJsonString());
                    }
                });
            }
            else
            {
                // Since there are no shipping methods available, it means that the shipping address that was set is unserviceable
                var summaryItems = GetSummaryItemsFromCheckout(CartState.CurrentCheckout);
                var payErrors    = new List <ApplePayError>();
                payErrors.Add(new ApplePayShippingAddressUnservicableError("Shipping address is in an unserviceable area"));
                message.Respond(new ApplePayEventResponse(ApplePayAuthorizationStatus.InvalidShippingPostalAddress, summaryItems, shippingMethods, payErrors).ToJsonString());
            }
        }
Пример #2
0
 /// <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);
         }
     });
 }
Пример #3
0
 /// <summary>
 /// Updates the shipping line and responds to Android plugin with the update status.
 /// </summary>
 /// <param name="shippingMethod">
 /// A <see cref="ShippingMethod"> object that will be used to update the shipping line.
 /// </param>
 /// <param name="message">
 /// A <see cref="NativeMessage"> object used to respond to the Android plugin side
 /// about the shipping line update.
 /// </param>
 private void UpdateShippingLine(ShippingMethod shippingMethod, NativeMessage message)
 {
     CartState.SetShippingLine(shippingMethod.Identifier, (ShopifyError error) => {
         if (error == null)
         {
             message.Respond(GetAndroidPayEventResponse().ToJsonString());
         }
         else
         {
             RespondError(message, error);
             OnFailure(error);
         }
     });
 }
Пример #4
0
        private void RespondToUpdateAddressErrorForMessage(NativeMessage message, ShopifyError error)
        {
            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 = GetUpdateRequestStatusFromPreliminaryShippingUserErrors(userErrors);
                if (status.AuthorizationStatus == ApplePayAuthorizationStatus.InvalidShippingPostalAddress)
                {
                    var summaryItems = GetSummaryItemsFromCheckout(CartState.CurrentCheckout);
                    response =
                        new ApplePayEventResponse(
                            authorizationStatus: status.AuthorizationStatus,
                            summaryItems: summaryItems,
                            errors: status.Errors
                            );
                }
            }

            message.Respond(response.ToJsonString());
        }
Пример #5
0
 /// <summary>
 /// Responds to the Android plugin side with an error.
 /// </summary>
 /// <param name="message">
 /// A <see cref="NativeMessage"> object used to respond
 /// to the Android plugin side about the error.
 /// </param>
 /// <param name="error">
 /// A <see cref="ShopifyError"> object that will be sent
 /// to the Android plugin side.
 /// </param>
 private void RespondError(NativeMessage message, ShopifyError error)
 {
     message.Respond(error.ToJsonString());
 }