public bool StornoCurrentTransaction() { ETransactionStatus status = api.Refund(current_transaction.Transaction_id, current_transaction.Amount_in_cents, "EUR"); current_transaction.Status = TransactionStatus.ToDatabaseStatus(status); database.UpdateTransaction(current_transaction); flow.state = StateHelper.GetCorrespondingState(this, status); return(true); }
private void LoadLastTransaction(OnlinePaymentFlow flow) { SMBillsTransaction last_transaction = database.GetLastTransaction(); if (last_transaction != null && last_transaction.Datetime_finished != null) { current_transaction = last_transaction; ETransactionStatus status = TransactionStatus.FromDatabaseStatus(current_transaction.Status); flow.state = StateHelper.GetCorrespondingState(this, status); } }
public static bool VoidTransaction(IOnlinePaymentFlowState state) { ETransactionStatus status = state.api.Void(state.current_transaction.Transaction_id, "Your payment reservation has been cancelled!"); if (status == ETransactionStatus.Voided) { PersistAndTransitionState(state, status); return(true); } else { return(false); } }
public bool FinishCurrentTransaction(string BiroStevilkaRacuna) { ETransactionStatus status = api.Capture(current_transaction.Transaction_id, current_transaction.Amount_in_cents, "Thank you for shopping with us!"); if (status == ETransactionStatus.Paid) { current_transaction.Biro_stevilka_racuna = BiroStevilkaRacuna; StateHelper.PersistAndTransitionState(this, status); return(true); } else { return(false); } }
public static bool RefreshTransaction(IOnlinePaymentFlowState state) { try { ETransactionStatus new_status = state.api.GetTransactionStatus(state.current_transaction.Transaction_id); ETransactionStatus current_status = TransactionStatus.FromDatabaseStatus(state.current_transaction.Status); if (new_status != current_status) { PersistAndTransitionState(state, new_status); } return(true); } catch (Exception ex) { return(false); } }
static void ApiWrapperTest() { // authenticate to the API MBillsAPIFacade api = new MBillsAPIFacade(); SAuthResponse response = api.testConnection(); Console.WriteLine("Response transaction ID: {0}", response.transactionId); // upload bill and POS sale string docid = api.UploadDocument(File.ReadAllText(GAppSettings.Get("RESOURCES_DIRECTORY") + @"\bill.xml")); int amount = 100; // start a sale SSaleResponse resp = api.Sale(100, docid); Console.WriteLine(JsonConvert.SerializeObject(resp)); // qr code api.getQRCode(resp.paymenttokennumber.ToString(), "temp.jpg"); while (true) { ETransactionStatus status = api.GetTransactionStatus(resp.transactionid); if (status == ETransactionStatus.Authorized) { Console.WriteLine(""); //status = api.Capture(resp.transactionid, amount, "Thank you for shopping with us!"); status = api.Void(resp.transactionid, "Sorry, but you stink so we won't do business with you!"); } if (status == ETransactionStatus.Paid) { break; } if (status == ETransactionStatus.Voided) { break; } Thread.Sleep(3000); } Console.ReadLine(); }
public static string ToDatabaseStatus(ETransactionStatus status) { return(Enum.GetName(typeof(ETransactionStatus), status)); }
public static void PersistAndTransitionState(IOnlinePaymentFlowState state, ETransactionStatus status) { state.current_transaction.Status = TransactionStatus.ToDatabaseStatus(status); state.database.UpdateTransaction(state.current_transaction); state.flow.state = GetCorrespondingState(state, status); }
public static IOnlinePaymentFlowState GetCorrespondingState(IOnlinePaymentFlowState state, ETransactionStatus status) { switch (status) { case ETransactionStatus.Accepted: return(new AcceptedState(state, state.flow)); case ETransactionStatus.Authorized: return(new AuthorizedState(state, state.flow)); case ETransactionStatus.InsufficientFunds: return(new UnpaidFinishedState(state, state.flow)); case ETransactionStatus.Paid: return(new PaidState(state, state.flow)); case ETransactionStatus.Pending: throw new Exception("Transaction was in pending state, which is unknown to us at this time."); case ETransactionStatus.RecurringCancelled: throw new Exception("Transaction was in RecurringCancelled state. We don't support recurring payments."); case ETransactionStatus.Rejected: return(new UnpaidFinishedState(state, state.flow)); case ETransactionStatus.TimeOut: return(new UnpaidFinishedState(state, state.flow)); case ETransactionStatus.TransactionAmountTooBig: return(new UnpaidFinishedState(state, state.flow)); case ETransactionStatus.TransactionAmountTooLow: return(new UnpaidFinishedState(state, state.flow)); default: return(null); } }
public static IOnlinePaymentFlowState GetCorrespondingState(string status, IOnlinePaymentFlowState state) { ETransactionStatus s = TransactionStatus.FromString(status); return(GetCorrespondingState(state, s)); }