/// <summary> /// Announces the MerchantOrder to OmniKassa and returns the payment URL /// </summary> /// <param name="order">Merchant order</param> /// <param name="token">Access token</param> /// <returns>Response with payment URL</returns> public Task <MerchantOrderResponse> AnnounceMerchantOrder(MerchantOrder order, String token) { DateTime now = DateTime.Now; order.Timestamp = now.ToString("s") + now.ToString("zzz"); return(PostAsync <MerchantOrderResponse>(mClient, PATH_ANNOUNCE_ORDER, token, order)); }
public async System.Threading.Tasks.Task <MerchantOrder> UpdateAsync(MerchantOrder merchantOrder) { if (merchantOrder is null) { this.AddNotification("merchantOrder", "merchantOrder is Required"); } if (this.IsInvalid()) { return(null); } var url = await MPUrlBuildAsync($"/v1/merchant_orders/{merchantOrder.Id}/"); var content = new StringContent(JsonConvert.SerializeObject(merchantOrder, MPUtil.JsonSerializerSettings), Encoding.UTF8, "application/json"); var response = await Client.PutAsync(url, content); string stringResponse = await this.ExtractResponseAsync(response); if (this.IsInvalid()) { return(null); } return(JsonConvert.DeserializeObject <MerchantOrder>(stringResponse, MPUtil.JsonSerializerSettings)); }
public void MerchantOrder_UpdateShouldBeOk() { SDK.CleanConfiguration(); SDK.SetBaseUrl("https://api.mercadopago.com"); Dictionary <string, string> config = new Dictionary <string, string>(); config.Add("clientSecret", Environment.GetEnvironmentVariable("CLIENT_SECRET")); config.Add("clientId", Environment.GetEnvironmentVariable("CLIENT_ID")); SDK.SetConfiguration(config); MerchantOrder merchantOrderInternal = new MerchantOrder() { ID = "1" }; try { var result = merchantOrderInternal.Update(); } catch (MPException mpException) { Assert.Fail(); } Assert.Pass(); }
private static MerchantOrder NewMerchantOrder() { var preference = PreferenceTest.NewPreference(); preference.Save(); var merchantOrder = new MerchantOrder { PreferenceId = preference.Id, Items = new List <Item>(), ApplicationId = "59441713004005", AdditionalInfo = "Aditional info", ExternalReference = Guid.NewGuid().ToString(), Marketplace = "NONE", NotificationUrl = "https://seller/notification", SiteId = "MLB", }; preference.Items.ForEach(item => { merchantOrder.Items.Add(new Item { ID = item.Id, CategoryId = item.CategoryId, CurrencyId = item.CurrencyId.ToString(), Description = item.Description, PictureUrl = item.PictureUrl, Quantity = item.Quantity.GetValueOrDefault(), Title = item.Title, UnitPrice = (float)item.UnitPrice, }); }); return(merchantOrder); }
public ActionResult PlaceOrder() { CreateOrderIfRequired(); webShopModel.PaymentCompleted = null; try { MerchantOrder order = OrderHelper.PrepareOrder(Request.Form, webShopModel); if (order != null) { MerchantOrderResponse response = omniKassa.Announce(order); webShopModel = null; SessionVar.Set <WebShopModel>(SESSION_ORDER, null); return(new RedirectResult(response.RedirectUrl)); } } catch (RabobankSdkException ex) { webShopModel.Error = ex.Message; } catch (ArgumentException ex) { webShopModel.Error = ex.Message; } return(View("Index", webShopModel)); }
public void MerchantOrder_ShouldValidateNullPreferenceId() { var merchantOrder = new MerchantOrder(); var validationResult = Validator.GetValidationResult(merchantOrder); var error = validationResult.Errors.FirstOrDefault(x => x.Code == ValidationError.RequiredErrorCode); Assert.IsNotNull(error, $"Failed to validate required property MerchantOrder.PreferenceId"); }
public string AnnounceMerchantOrder(MerchantOrder merchantOrder) { var request = new MerchantOrderRequest(merchantOrder, _signingKey); var responseAsJson = _connector.AnnounceMerchantOrder(request); var response = Response.CreateInstance <MerchantOrderResponse>(responseAsJson, _signingKey); return(response.RedirectUrl); }
public void MerchantOrder_AppendShipmentShouldBeOk() { MerchantOrder merchantOrderInternal = new MerchantOrder(); merchantOrderInternal.AppendShipment(new Shipment() { }); Assert.Pass(); }
public void Create_Success() { MerchantOrderCreateRequest request = BuildCreateRequest(); MerchantOrder merchantOrder = client.Create(request); Assert.NotNull(merchantOrder); Assert.NotNull(merchantOrder.Id); Assert.Equal(request.ExternalReference, merchantOrder.ExternalReference); }
public async Task CreateAsync_Success() { MerchantOrderCreateRequest request = await BuildCreateRequestAsync(); MerchantOrder merchantOrder = await client.CreateAsync(request); Assert.NotNull(merchantOrder); Assert.NotNull(merchantOrder.Id); Assert.Equal(request.ExternalReference, merchantOrder.ExternalReference); }
public void MerchantOrder_AppendItemShouldBeOk() { MerchantOrder merchantOrderInternal = new MerchantOrder(); merchantOrderInternal.Items = new List <Item>(); merchantOrderInternal.AppendItem(new Item() { }); Assert.Pass(); }
public void MerchantOrder_ItemsShouldHaveAtLeastOneItem() { MerchantOrder merchantOrderInternal = new MerchantOrder(); merchantOrderInternal.AppendItem(new Item() { Description = "Item de compra" }); Assert.AreEqual("Item de compra", merchantOrderInternal.Items.FirstOrDefault().Description); }
public void MerchantOrder_ShipmentsShouldHaveAtLeastOneItem() { MerchantOrder merchantOrderInternal = new MerchantOrder(); merchantOrderInternal.AppendShipment(new Shipment() { ShipmentType = "Aereo" }); Assert.AreEqual("Aereo", merchantOrderInternal.Shipments.FirstOrDefault().ShipmentType); }
public void Get_Success() { MerchantOrderCreateRequest createRequest = BuildCreateRequest(); MerchantOrder createdOrder = client.Create(createRequest); Thread.Sleep(1000); MerchantOrder merchantOrder = client.Get(createdOrder.Id.GetValueOrDefault()); Assert.NotNull(merchantOrder); Assert.Equal(createdOrder.Id, merchantOrder.Id); }
public async Task <ActionResult> PlaceOrder() { try { MerchantOrder order = GetOrder(); MerchantOrderResponse response = await omniKassa.Announce(order); return(new RedirectResult(response.RedirectUrl)); } catch (RabobankSdkException) { return(View("Index")); } }
public async Task GetAsync_Success() { MerchantOrderCreateRequest createRequest = await BuildCreateRequestAsync(); MerchantOrder createdOrder = await client.CreateAsync(createRequest); await Task.Delay(1000); MerchantOrder merchantOrder = await client.GetAsync( createdOrder.Id.GetValueOrDefault()); Assert.NotNull(merchantOrder); Assert.Equal(createdOrder.Id, merchantOrder.Id); }
public static HttpResponseMessage Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "notification/get/{id}")] HttpRequest httpRequest, [Table("qrorders", "qr", "{id}")] MerchantOrder merchantOrder, ILogger log) { if (merchantOrder != null) { return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(merchantOrder.Json, Encoding.UTF8, "application/json") }); } return(new HttpResponseMessage(HttpStatusCode.NotFound)); }
public void MerchantOrderLoadTest() { var merchantOrder = NewMerchantOrder(); merchantOrder.Save(); Assert.IsNotNull(merchantOrder.ID); var loadMerchantOrder = new MerchantOrder { ID = merchantOrder.ID, }; loadMerchantOrder.Load(merchantOrder.ID); Assert.IsNull(loadMerchantOrder.Errors); Assert.AreEqual(merchantOrder.ID, loadMerchantOrder.ID); }
/// <summary> /// Announces the MerchantOrder to OmniKassa and returns the payment URL and OmniKassa order ID /// </summary> /// <param name="merchantOrder">Merchant order</param> /// <returns>Holder object containing payment URL and OmniKassa order ID</returns> public MerchantOrderResponse Announce(MerchantOrder merchantOrder) { ValidateAccessToken(); try { return(httpClient.AnnounceMerchantOrder(merchantOrder, tokenProvider.GetAccessToken())); } catch (InvalidAccessTokenException) { // We might have mistakenly assumed the token was still valid RetrieveNewToken(); return(httpClient.AnnounceMerchantOrder(merchantOrder, tokenProvider.GetAccessToken())); } }
public void Update_Success() { MerchantOrderCreateRequest createRequest = BuildCreateRequest(); MerchantOrder createdOrder = client.Create(createRequest); Thread.Sleep(1000); var updateRequest = new MerchantOrderUpdateRequest { AdditionalInfo = "New Additional Info", }; MerchantOrder order = client.Update( createdOrder.Id.GetValueOrDefault(), updateRequest); Assert.NotNull(order); Assert.NotNull(order.Items); Assert.Equal(updateRequest.AdditionalInfo, order.AdditionalInfo); }
public async Task UpdateAsync_Success() { MerchantOrderCreateRequest createRequest = await BuildCreateRequestAsync(); MerchantOrder createdOrder = await client.CreateAsync(createRequest); await Task.Delay(1000); var updateRequest = new MerchantOrderUpdateRequest { AdditionalInfo = "New Additional Info", }; MerchantOrder order = await client.UpdateAsync( createdOrder.Id.GetValueOrDefault(), updateRequest); Assert.NotNull(order); Assert.NotNull(order.Items); Assert.Equal(updateRequest.AdditionalInfo, order.AdditionalInfo); }
public void MerchantOrder_UpdateShouldRaiseException() { MerchantOrder merchantOrderInternal = new MerchantOrder() { ID = "1" }; merchantOrderInternal.ID = "2"; try { var result = merchantOrderInternal.Update(); } catch (MPException mpException) { Assert.AreEqual("\"client_id\" and \"client_secret\" can not be \"null\" when getting the \"access_token\"", mpException.Message); } Assert.Pass(); }
public Task <MerchantOrder> ProcessMerchantOrder(PaymentRequest payRequest) { try { // Generate random receipt number for order Random randomObj = new Random(); string transactionId = randomObj.Next(10000000, 100000000).ToString(); Razorpay.Api.RazorpayClient client = new Razorpay.Api.RazorpayClient("rzp_test_8P7RhnsImxd2OR", "kD8tw7ECYsTTZnx0OyrKI4kh"); Dictionary <string, object> options = new Dictionary <string, object>(); options.Add("amount", payRequest.Amount * 100); options.Add("receipt", transactionId); options.Add("currency", "INR"); options.Add("payment_capture", "0"); // 1 - automatic , 0 - manual //options.Add("Notes", "Test Payment of Merchant"); Razorpay.Api.Order orderResponse = client.Order.Create(options); string orderId = orderResponse["id"].ToString(); MerchantOrder order = new MerchantOrder { OrderId = orderResponse.Attributes["id"], RazorpayKey = "rzp_test_8P7RhnsImxd2OR", Amount = payRequest.Amount * 100, Currency = "INR", Name = payRequest.Name, Email = payRequest.Email, PhoneNumber = payRequest.PhoneNumber, Address = payRequest.Address, Description = "Order by Merchant" }; return(Task.FromResult(order)); } catch (Exception ex) { throw; } }
public void Search_Success() { MerchantOrderCreateRequest createRequest = BuildCreateRequest(); MerchantOrder createdOrder = client.Create(createRequest); Thread.Sleep(3000); var searchRequest = new SearchRequest { Limit = 1, Offset = 0, Filters = new Dictionary <string, object> { ["external_reference"] = createRequest.ExternalReference, }, }; ElementsResourcesPage <MerchantOrder> results = client.Search(searchRequest); Assert.NotNull(results); Assert.Equal(1, results.Total); Assert.NotNull(results.Elements); Assert.Equal(createdOrder.Id, results.Elements.First().Id); }
public void MPIPN_MerchantOrderNotification_MustBeOk() { SDK.CleanConfiguration(); SDK.AccessToken = Environment.GetEnvironmentVariable("ACCESS_TOKEN"); var merchantOrder = new MerchantOrder { Payer = new MercadoPago.DataStructures.MerchantOrder.Payer { Email = "*****@*****.**" }, Items = new List <Item> { new Item { Description = "Test Ipn", Quantity = 1, UnitPrice = 10m } } }; merchantOrder.Save(); Ipn.HandleNotification(Ipn.MerchantOrder, merchantOrder.Id, onPaymentReceived: null, onMerchantOrderReceived: m => { Assert.AreEqual(m.Id, merchantOrder.Id); Assert.AreEqual(m.Items.Count, merchantOrder.Items.Count); Assert.AreEqual(m.Items[0].UnitPrice, merchantOrder.Items[0].UnitPrice); Assert.AreEqual(m.Items[0].Description, merchantOrder.Items[0].Description); Assert.Pass(); }); Assert.Fail(); }
public async Task SearchAsync_Success() { MerchantOrderCreateRequest createRequest = await BuildCreateRequestAsync(); MerchantOrder createdOrder = await client.CreateAsync(createRequest); await Task.Delay(3000); var searchRequest = new SearchRequest { Limit = 1, Offset = 0, Filters = new Dictionary <string, object> { ["external_reference"] = createRequest.ExternalReference, }, }; ElementsResourcesPage <MerchantOrder> results = await client.SearchAsync(searchRequest); Assert.NotNull(results); Assert.Equal(1, results.Total); Assert.NotNull(results.Elements); Assert.Equal(createdOrder.Id, results.Elements.First().Id); }
protected void Page_Load(object sender, EventArgs e) { var orderItems = new[] { new OrderItem { Id = "1", Name = "Test product", Description = "Description", Quantity = 1, Amount = Money.FromDecimal("EUR", 99.99), Tax = Money.FromDecimal("EUR", 20.99), Category = ProductType.Digital, VatCategory = VatCategory.High } }; var shippingDetail = new Address { FirstName = "Jan", MiddleName = "van", LastName = "Veen", Street = "Voorbeeldstraat", PostalCode = "1234AB", City = "Haarlem", CountryCode = "NL", HouseNumber = "5", HouseNumberAddition = "a" }; var billingDetail = new Address { FirstName = "Jan", MiddleName = "van", LastName = "Veen", Street = "Factuurstraat", PostalCode = "2314AB", City = "Haarlem", CountryCode = "NL", HouseNumber = "15", }; var customerInformation = new CustomerInformation { EmailAddress = "*****@*****.**", DateOfBirth = new DateTime(1987, 3, 20), Gender = "M", Initials = "J.M.", TelephoneNumber = "0204971111" }; var order = new MerchantOrder { MerchantOrderId = "100", Description = "Order ID: 100", OrderItems = orderItems, Amount = Money.FromDecimal("EUR", 99.99), ShippingDetail = shippingDetail, BillingDetail = billingDetail, CustomerInformation = customerInformation, Language = "NL", MerchantReturnUrl = "http://localhost/", PaymentBrand = PaymentBrand.Ideal, PaymentBrandForce = PaymentBrandForce.ForceOnce }; var refreshToken = WebConfigurationManager.AppSettings["RefreshToken"]; var signingKey = WebConfigurationManager.AppSettings["SigningKey"]; var testMode = bool.Parse(WebConfigurationManager.AppSettings["TestMode"]); var client = new OmniKassaApiClient(refreshToken, signingKey, testMode); var redirectUrl = client.AnnounceMerchantOrder(order); //Redirect user to Rabo OmniKassa Response.Redirect(redirectUrl, true); }
public async Task <IActionResult> ProcessRequestOrder(PaymentRequest _paymentRequest) { MerchantOrder _marchantOrder = await _service.ProcessMerchantOrder(_paymentRequest); return(View("Payment", _marchantOrder)); }
/// <summary> /// Announces the MerchantOrder to OmniKassa and returns the payment URL /// </summary> /// <param name="merchantOrder">Merchant order</param> /// <returns>Payment URL</returns> public string AnnounceMerchantOrder(MerchantOrder merchantOrder) { CheckOmniKassaInterface(); return(_omniKassa.AnnounceMerchantOrder(merchantOrder)); }
public string AnnounceMerchantOrder(MerchantOrder merchantOrder) { return(Announce(merchantOrder).RedirectUrl); }