/// <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); } }); }
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()); } }); }
private void SetFinalCheckoutFieldsForPayment(NativePayment payment, Checkout checkout, ApplePayEventHandlerCompletion callback) { ShippingFields?shippingFields = null; if (checkout.requiresShipping()) { shippingFields = new ShippingFields(payment.ShippingAddress, payment.ShippingIdentifier); } CartState.SetFinalCheckoutFields(payment.Email, shippingFields, (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 = GetUpdateRequestStatusFromShippingUserErrors(userErrors); var summaryItems = GetSummaryItemsFromCheckout(CartState.CurrentCheckout); if (status.AuthorizationStatus == ApplePayAuthorizationStatus.InvalidShippingPostalAddress) { response = new ApplePayEventResponse( authorizationStatus: status.AuthorizationStatus, summaryItems: summaryItems, errors: status.Errors ); } else if (status.AuthorizationStatus == ApplePayAuthorizationStatus.InvalidShippingContact) { response = new ApplePayEventResponse( status.AuthorizationStatus, summaryItems, GetShippingMethods(), status.Errors ); } } callback(response); } }); }