/// <summary> /// Recovery for when the PoS crashes /// </summary> private void InvokeRecovery() { var currentPosRefId = Settings.CurrentPosRefId; // no need for recovery if (Settings.TransactionComplete || currentPosRefId == "") { return; } // initiate recovery switch (Settings.TransactionState) { case "MOTO": var motoRecovery = SpiceApiLib.Moto(currentPosRefId, PosName, _posVersion); if (motoRecovery.IsSuccessStatusCode) { DisplayResult(motoRecovery.Content.ReadAsStringAsync().Result); } break; case "Purchase": var purchaseRecovery = SpiceApiLib.Purchase(currentPosRefId, PosName, _posVersion); if (purchaseRecovery.IsSuccessStatusCode) { DisplayResult(purchaseRecovery.Content.ReadAsStringAsync().Result); } break; case "Refund": var refundRecovery = SpiceApiLib.Refund(currentPosRefId, PosName, _posVersion); if (refundRecovery.IsSuccessStatusCode) { DisplayResult(refundRecovery.Content.ReadAsStringAsync().Result); } break; } // transaction complete Settings.TransactionComplete = true; Settings.Save(); }
private void btnAction_Click(object sender, EventArgs e) { // set transaction incomplete Settings.TransactionComplete = false; Settings.TransactionState = btnAction.Text; Settings.Save(); if (string.Equals(btnAction.Text, "OK")) { lblResult.Text = string.Empty; ResetControls(); return; } if (!IsAdaptorPaired()) { DisplayResultHelper("Please check your adaptor"); return; } switch (btnAction.Text) { case "Purchase": bool purchaseParsed, cashoutParsed, tipParsed, surchargeParsed; purchaseParsed = int.TryParse(txtPurchase.Text, NumberStyles.Currency, this._cultureInfo, out var purchaseAmount); cashoutParsed = int.TryParse(txtCashout.Text, NumberStyles.Currency, this._cultureInfo, out var cashoutAmount); tipParsed = int.TryParse(txtTip.Text, NumberStyles.Currency, this._cultureInfo, out var tipAmount); surchargeParsed = int.TryParse(txtSurcharge.Text, NumberStyles.Currency, this._cultureInfo, out var surchargeAmount); if (purchaseParsed && cashoutParsed && tipParsed && surchargeParsed) { var response = SpiceApiLib.Purchase(PosRefIdHelper(), purchaseAmount, tipAmount, cashoutAmount, rbCashoutYes.Checked, surchargeAmount, PosName, _posVersion); if (response.IsSuccessStatusCode) { DisplayResult(response.Content.ReadAsStringAsync().Result); IsSignatureRequired(response.Content.ReadAsStringAsync().Result, TransactionType.purchase); } else if (response.StatusCode == HttpStatusCode.RequestTimeout) { // Manual Override https://developer.assemblypayments.com/docs/manual-user-override } } break; case "MOTO": bool motoPurchaseParsed, motoSurchargeParsed; motoPurchaseParsed = int.TryParse(txtMotoPurchase.Text, NumberStyles.Currency, this._cultureInfo, out var motoPurchaseAmount); motoSurchargeParsed = int.TryParse(txtMotoSurcharge.Text, NumberStyles.Currency, this._cultureInfo, out var motoSurchargeAmount); if (motoPurchaseParsed && motoSurchargeParsed) { var response = SpiceApiLib.Moto(PosRefIdHelper(), motoPurchaseAmount, motoSurchargeAmount, rbSuppressPasswordYes.Checked, PosName, _posVersion); if (response.IsSuccessStatusCode) { DisplayResult(response.Content.ReadAsStringAsync().Result); } } break; case "Refund": bool refundParsed; refundParsed = int.TryParse(txtRefund.Text, NumberStyles.Currency, this._cultureInfo, out var refundAmount); if (refundParsed) { var response = SpiceApiLib.Refund(PosRefIdHelper(), refundAmount, rbRefundSuppressPasswordYes.Checked, PosName, _posVersion); if (response.IsSuccessStatusCode) { DisplayResult(response.Content.ReadAsStringAsync().Result); IsSignatureRequired(response.Content.ReadAsStringAsync().Result, TransactionType.refund); } else if (response.StatusCode == HttpStatusCode.RequestTimeout) { // Manual Override https://developer.assemblypayments.com/docs/manual-user-override } } break; case "Enquiry": var enquiry = SpiceApiLib.SettlementEnquiry(PosRefIdHelper(), PosName, _posVersion); DisplayResult(enquiry.Content.ReadAsStringAsync().Result); break; case "Pay at Table": break; } Settings.TransactionComplete = true; Settings.Save(); }