public void PaymentRequestCompleteInitsWithNoArgs() { var paymentRequestComplete = new PaymentRequestComplete(); Assert.NotNull(paymentRequestComplete); Assert.IsType <PaymentRequestComplete>(paymentRequestComplete); }
public void PaymentRequestCompleteInits() { var id = "id"; var paymentRequest = new PaymentRequest( "paymentId", new List <PaymentMethodData>() { new PaymentMethodData(new List <string> { "credit", "debit" }) }, new PaymentDetails(), new PaymentOptions(true, true, true)); var paymentResponse = new PaymentResponse("credit", new { }, new PaymentAddress(), "ground", "*****@*****.**", "555-555-5555"); var paymentRequestComplete = new PaymentRequestComplete(id, paymentRequest, paymentResponse); Assert.NotNull(paymentRequestComplete); Assert.IsType <PaymentRequestComplete>(paymentRequestComplete); Assert.Equal(id, paymentRequestComplete.Id); Assert.Equal(paymentRequest, paymentRequestComplete.PaymentRequest); Assert.Equal(paymentResponse, paymentRequestComplete.PaymentResponse); }
/* * private async Task<PaymentRequestUpdateResult> ProcessShippingUpdate(PaymentRequestUpdate paymentRequestUpdate, ShippingUpdateKind updateKind, CancellationToken token = default(CancellationToken)) * { * var catalogItem = await this.catalogService.GetItemByIdAsync(Guid.Parse(paymentRequestUpdate.Id)); * if (catalogItem == null) * { * throw new ArgumentException("Invalid cart identifier within payment request provided."); * } * * var result = new PaymentRequestUpdateResult(paymentRequestUpdate.Details); * if (ShippingUpdateKind.Both.Equals(updateKind) || ShippingUpdateKind.Address.Equals(updateKind)) * { * result.Details.ShippingOptions = (await this.shippingService.GetShippingOptionsAsync(catalogItem, paymentRequestUpdate.ShippingAddress)).ToList(); * } * * if (ShippingUpdateKind.Both.Equals(updateKind) || ShippingUpdateKind.Options.Equals(updateKind)) * { * foreach (var shippingOption in result.Details.ShippingOptions) * { * shippingOption.Selected = shippingOption.Id.Equals(paymentRequestUpdate.ShippingOption, StringComparison.OrdinalIgnoreCase); * } * } * * if (result.Details.ShippingOptions.Count(option => option.Selected.HasValue && option.Selected.Value) != 1) * { * throw new ArgumentException("Expected exactly zero or one selected shipping option."); * } * * // update payment details after shipping changed * await this.shippingService.UpdatePaymentDetailsAsync(result.Details, paymentRequestUpdate.ShippingAddress, catalogItem); * * return result; * } */ private async Task <PaymentRequestCompleteResult> ProcessPaymentComplete(IInvokeActivity invoke, PaymentRequestComplete paymentRequestComplete, CancellationToken token = default(CancellationToken)) { var paymentRequest = paymentRequestComplete.PaymentRequest; var paymentResponse = paymentRequestComplete.PaymentResponse; /* * paymentRequest.Details = (await this.ProcessShippingUpdate( * new PaymentRequestUpdate() * { * Id = paymentRequest.Id, * Details = paymentRequest.Details, * ShippingAddress = paymentResponse.ShippingAddress, * ShippingOption = paymentResponse.ShippingOption * }, * ShippingUpdateKind.Both, * token)).Details; */ PaymentRecord paymentRecord = null; PaymentRequestCompleteResult result = null; Exception paymentProcessingException = null; try { paymentRecord = await this.paymentService.ProcessPaymentAsync(paymentRequest, paymentResponse); result = new PaymentRequestCompleteResult("success"); } catch (Exception ex) { paymentProcessingException = ex; // TODO: If payment is captured but not charged this would be considered "unknown" (charge the captured amount after shipping scenario). result = new PaymentRequestCompleteResult("failure"); } try { var message = invoke.RelatesTo.GetPostToBotMessage(); if (result.Result == "success") { // Resume the conversation with the receipt to user message.Text = paymentRequestComplete.Id; message.Value = paymentRecord; /* * StateClient stateClient = invoke.GetStateClient(); * * BotData userData = await stateClient.BotState.GetConversationDataAsync(invoke.ChannelId, invoke.Conversation.Id); * userData.SetProperty<PaymentRecord>("PaymentRecord", paymentRecord); * await stateClient.BotState.SetUserDataAsync(invoke.ChannelId, invoke.Conversation.Id, userData); */ } else { // Resume the conversation with error message message.Text = $"Failed to process payment with error: {paymentProcessingException?.Message}"; } await Conversation.ResumeAsync(invoke.RelatesTo, message, token); } catch (Exception ex) { Trace.TraceError($"Failed to resume the conversation using ConversationReference: {JsonConvert.SerializeObject(invoke.RelatesTo)} and exception: {ex.Message}"); } return(result); }