// TODO - GenerateCreditCardPayment(). public object GenerateCreditCardPayment( Models.Customer loggedInCustomer, ShippingInformation shippingInfo, Models.Address customerAddress, List <CartItem> cartItems, CreditCard creditCart) { try { SetKeys(); decimal totalPrice = CalculateTotalPrice(cartItems, shippingInfo); Transaction transaction = new Transaction() { Amount = PriceConverter.ConvertDecimalPriceToPriceInCents(totalPrice), Billing = BillingFactory(loggedInCustomer, customerAddress), Card = CardFactory(creditCart), Customer = CustomerFactory(loggedInCustomer), Item = ItemArrayFactory(cartItems), Shipping = ShippingFactory(loggedInCustomer, shippingInfo, customerAddress) }; transaction.Save(); return(new { TransactionId = transaction.Id }); } catch (Exception e) { return(new { Error = e.Message }); } }
private PagarMe.Item[] ItemArrayFactory(List <CartItem> cartItems) { Item[] itemArray = new Item[cartItems.Count]; for (int i = 0; i < cartItems.Count; i++) { CartItem currentCartItem = cartItems[i]; itemArray[i] = new Item() { Id = currentCartItem.Id.ToString(), Title = currentCartItem.Product.Name, Quantity = currentCartItem.Amount, Tangible = true, UnitPrice = PriceConverter.ConvertDecimalPriceToPriceInCents(currentCartItem.Product.UnitPrice) }; } return(itemArray); }
public object GenerateBoleto(Models.Customer loggedInCustomer, decimal totalPrice) { try { SetKeys(); Transaction transaction = new Transaction() { Amount = PriceConverter.ConvertDecimalPriceToPriceInCents(totalPrice), PaymentMethod = PaymentMethod.Boleto, Customer = CustomerFactory(loggedInCustomer) }; transaction.Save(); return(new { BoletoUrl = transaction.BoletoUrl, ExpirationDate = transaction.BoletoExpirationDate }); } catch (Exception e) { return(new { Error = e.Message }); } }