public BitPayTest2() { try { // If this test has never been run before then this test must be run twice in order to pass. // The first time this test runs it will create an identity and emit a client pairing code. // The pairing code must then be authorized in a BitPay account. Running the test a second // time should result in the authorized client (this test) running to completion. bitpay = new BitPay(clientName); if (!bitpay.clientIsAuthorized(BitPay.FACADE_POS)) { // Get POS facade authorization code. // Obtain a pairingCode from the BitPay server. The pairingCode must be emitted from // this device and input into and approved by the desired merchant account. To // generate invoices a POS facade is required. String pairingCode = bitpay.requestClientAuthorization(BitPay.FACADE_POS); // Signal the device operator that this client needs to be paired with a merchant account. System.Diagnostics.Debug.WriteLine("Info: Pair this client with your merchant account using the pairing code: " + pairingCode); throw new BitPayException("Error: client is not yet authorized, pair this client with your BitPay merchant account using the pairing code: " + pairingCode); } } catch (Exception ex) { Assert.Fail(ex.Message); } }
/// <summary> /// Constructor. Creates the Rates instance from the BitPay server response. /// </summary> /// <param name="response">The raw HTTP response from BitPay server api/rates call.</param> /// <param name="bp">bp - used to update self.</param> public Rates(HttpContent response, BitPay bp) { dynamic obj = Json.Decode(response.ReadAsStringAsync().Result); this._bp = bp; _rates = new List<Rate>(); foreach (dynamic rateObj in obj) { _rates.Add(new Rate(rateObj.name, rateObj.code, rateObj.rate)); } }
/// <summary> /// Constructor. Creates the Rates instance from the BitPay server response. /// </summary> /// <param name="response">The raw HTTP response from BitPay server api/rates call.</param> /// <param name="bp">bp - used to update self.</param> public Rates(HttpContent response, BitPay bp) { dynamic obj = Json.Decode(response.ReadAsStringAsync().Result); this._bp = bp; _rates = new List <Rate>(); foreach (dynamic rateObj in obj) { _rates.Add(new Rate(rateObj.name, rateObj.code, rateObj.rate)); } }
public ActionResult IPNHandler() { var stream = new StreamReader(_httpContext.Request.InputStream); var invoice = JsonConvert.DeserializeObject <Invoice>(stream.ReadToEnd()); if (invoice == null) { return(Content("")); } var id = invoice.Id; var bitpay = new BitPayAPI.BitPay(envUrl: BitpayHelper.GetEnvironmentUrl(_bitpaySettings)); invoice = bitpay.getInvoice(id); var order = _orderService.GetOrderById(int.Parse(invoice.PosData)); if (order == null) { return(Content("")); } order.OrderNotes.Add(new OrderNote { CreatedOnUtc = DateTime.UtcNow, DisplayToCustomer = false, Note = $"Bitpay IPN handler. Incoming status is: {invoice.Status}" }); _orderService.UpdateOrder(order); switch (invoice.Status) { case "new": break; case "paid": case "confirmed": case "complete": if (_orderProcessingService.CanMarkOrderAsPaid(order)) { _orderProcessingService.MarkOrderAsPaid(order); } break; default: break; } return(Content("")); }
public ActionResult Configure(ConfigurationModel model) { if (!ModelState.IsValid) { return(Configure()); } //load settings for a chosen store scope var storeScope = this.GetActiveStoreScopeConfiguration(_storeService, _workContext); var bitpaySettings = _settingService.LoadSetting <BitpayPaymentSettings>(storeScope); // pair client with server if (!model.PairingCode.Equals(bitpaySettings.PairingCode, StringComparison.InvariantCultureIgnoreCase)) { var bitpay = new BitPayAPI.BitPay(envUrl: BitpayHelper.GetEnvironmentUrl(bitpaySettings)); if (!bitpay.clientIsAuthorized(BitPayAPI.BitPay.FACADE_POS)) { bitpay.authorizeClient(model.PairingCode); } } //save settings bitpaySettings.PairingCode = model.PairingCode; bitpaySettings.UseSandbox = model.UseSandbox; bitpaySettings.CustomUrl = model.CustomUrl; bitpaySettings.TransactionSpeed = (TransactionSpeed)model.TransactionSpeedId; /* We do not clear cache after each setting update. * This behavior can increase performance because cached settings will not be cleared * and loaded from database after each update */ _settingService.SaveSettingOverridablePerStore(bitpaySettings, x => x.PairingCode, model.PairingCode_OverrideForStore, storeScope, false); _settingService.SaveSettingOverridablePerStore(bitpaySettings, x => x.CustomUrl, model.CustomUrl_OverrideForStore, storeScope, false); _settingService.SaveSettingOverridablePerStore(bitpaySettings, x => x.UseSandbox, model.UseSandbox_OverrideForStore, storeScope, false); _settingService.SaveSettingOverridablePerStore(bitpaySettings, x => x.TransactionSpeed, model.TransactionSpeed_OverrideForStore, storeScope, false); //now clear settings cache _settingService.ClearCache(); SuccessNotification(_localizationService.GetResource("Admin.Plugins.Saved")); return(Configure()); }
public BitPayTest() { try { // This scenario qualifies that this (test) client does not have merchant facade access. bitpay = new BitPay(clientName); if (!bitpay.clientIsAuthorized(BitPay.FACADE_POS)) { // Get POS facade authorization. // Obtain a pairingCode from your BitPay account administrator. When the pairingCode // is created by your administrator it is assigned a facade. To generate invoices a // POS facade is required. bitpay.authorizeClient(pairingCode); } } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void testShouldCreateInvoice100USD() { try { // Arrange double price = 100.0; double expected = 100.0; // Act this.bitpay = new BitPay(API_KEY); Invoice invoice = this.bitpay.createInvoice(price, "USD"); // Assert double actual = invoice.price; Assert.AreEqual(expected, actual, EPSILON, "Invoice not created correctly: 100USD"); } catch (BitPayException ex) { Assert.Fail(ex.getMessage()); } }
public BitPayTest() { double price = 100.0; this.bitpay = new BitPay(API_KEY); basicInvoice = this.bitpay.createInvoice(price, "USD"); }
public Rates(List <Rate> rates, BitPay bp) { _bp = bp; _rates = rates; }
/// <summary> /// Post process payment (used by payment gateways that require redirecting to a third-party URL) /// </summary> /// <param name="postProcessPaymentRequest">Payment info required for an order processing</param> public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest) { var invoice = new Invoice { BuyerName = $"{postProcessPaymentRequest.Order.BillingAddress.FirstName} {postProcessPaymentRequest.Order.BillingAddress.LastName}", BuyerEmail = postProcessPaymentRequest.Order.BillingAddress.Email, BuyerAddress1 = postProcessPaymentRequest.Order.BillingAddress.Address1, BuyerAddress2 = postProcessPaymentRequest.Order.BillingAddress.Address2, BuyerCity = postProcessPaymentRequest.Order.BillingAddress.City, TransactionSpeed = _bitpaySettings.TransactionSpeed.ToString().ToLowerInvariant(), OrderId = postProcessPaymentRequest.Order.Id.ToString(), PosData = postProcessPaymentRequest.Order.Id.ToString(), Currency = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode, NotificationURL = $"{_webHelper.GetStoreLocation()}Plugins/PaymentBitpay/IPNHandler", RedirectURL = $"{_webHelper.GetStoreLocation()}orderdetails/{postProcessPaymentRequest.Order.Id}", FullNotifications = true, Price = Convert.ToDouble(postProcessPaymentRequest.Order.OrderTotal) }; if (postProcessPaymentRequest.Order.BillingAddress.StateProvince != null) { invoice.BuyerState = postProcessPaymentRequest.Order.BillingAddress.StateProvince.Abbreviation; } if (postProcessPaymentRequest.Order.BillingAddress.Country != null) { invoice.BuyerCountry = postProcessPaymentRequest.Order.BillingAddress.Country.TwoLetterIsoCode; } var bitpay = new BitPayAPI.BitPay(envUrl: BitpayHelper.GetEnvironmentUrl(_bitpaySettings)); try { invoice = bitpay.createInvoice(invoice); if (!string.IsNullOrEmpty(invoice.Id)) { postProcessPaymentRequest.Order.OrderNotes.Add(new OrderNote { CreatedOnUtc = DateTime.UtcNow, DisplayToCustomer = false, Note = $"Invoice initiated successfully. Id: {invoice.Id}, Status: {invoice.Status}" }); postProcessPaymentRequest.Order.AuthorizationTransactionId = invoice.Id; } } catch (Exception ex) { _logger.Error("Error creating invoice", ex); postProcessPaymentRequest.Order.OrderNotes.Add(new OrderNote { CreatedOnUtc = DateTime.UtcNow, DisplayToCustomer = false, Note = $"Error creating invoice: {ex.Message}" }); } _orderService.UpdateOrder(postProcessPaymentRequest.Order); if (!string.IsNullOrEmpty(invoice.Id)) { _httpContext.Response.Redirect(invoice.Url); } }
public void testShouldCreateInvoiceWithAdditionalParams() { try { // Arrange double price = 100.0; InvoiceParams parameters = new InvoiceParams(); parameters.buyerName = "Satoshi"; parameters.buyerEmail = "*****@*****.**"; parameters.fullNotifications = true; parameters.notificationEmail = "*****@*****.**"; // Act this.bitpay = new BitPay(API_KEY); Invoice invoice = this.bitpay.createInvoice(price, "USD", parameters); // Assert Assert.IsNotNull(invoice, "Invoice not created"); } catch (BitPayException ex) { Assert.Fail(ex.getMessage()); } }
public Rates(List<Rate> rates, BitPay bp) { _bp = bp; _rates = rates; }
public void testShouldCreateInvoiceOneTenthBTC() { try { // Arrange double price = 0.1; double expected = 0.1; // Act this.bitpay = new BitPay(API_KEY); Invoice invoice = this.bitpay.createInvoice(price, "BTC"); // Assert double actual = invoice.btcPrice; Assert.AreEqual(expected, actual, BTC_EPSILON, "Invoice not created correctly: 0.1BTC"); } catch (BitPayException ex) { Assert.Fail(ex.getMessage()); } }
public void testShouldUpdateExchangeRates() { // Arrange // Act this.bitpay = new BitPay(API_KEY); Rates rates = this.bitpay.getRates(); rates.update(); // Assert List<Rate> listRates = rates.getRates(); Assert.IsNotNull(listRates, "Exchange rates not retrieved after update"); }
public void testShouldGetUSDExchangeRate() { // Arrange // Act this.bitpay = new BitPay(API_KEY); Rates rates = this.bitpay.getRates(); // Assert decimal rate = rates.getRate("USD"); Assert.IsTrue(rate != 0, "Exchange rate not retrieved: USD"); }
public void testShouldGetInvoice() { try { // Arrange double price = 100.0; // Act this.bitpay = new BitPay(API_KEY); Invoice invoice = this.bitpay.createInvoice(price, "EUR"); Invoice retreivedInvoice = this.bitpay.getInvoice(invoice.id); // Assert string expected = invoice.id; string actual = retreivedInvoice.id; Assert.AreEqual(expected, actual, "Expected invoice not retreived"); } catch (BitPayException ex) { Assert.Fail(ex.getMessage()); } }
public void testShouldGetExchangeRates() { try { // Arrange // Act this.bitpay = new BitPay(API_KEY); Rates rates = this.bitpay.getRates(); // Assert List<Rate> listRates = rates.getRates(); Assert.IsNotNull(listRates, "Exchange rates not retrieved"); } catch (BitPayException ex) { Assert.Fail(ex.getMessage()); } }