private void IsSignatureRequired(string data, TransactionType transactionType) { HttpResponseMessage response; // https://developer.assemblypayments.com/docs/signature-transaction var currentPosRefId = Settings.CurrentPosRefId; // check if signature is required var result = (JObject)JsonConvert.DeserializeObject(data); // need a better way var value = result.GetValue("signatureRequired", StringComparison.OrdinalIgnoreCase); if (value == null) { return; } // signature accept or decline, get result from Assembly Payments Adaptor if (transactionType == 0) { response = SpiceApiLib.Purchase(currentPosRefId, PosName, _posVersion); } else { response = SpiceApiLib.Refund(currentPosRefId, PosName, _posVersion); } // customer receipt DisplayResult(response.Content.ReadAsStringAsync().Result); return; }
/// <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(); }