/// <summary> /// Performs checkout operation /// </summary> /// <param name="spaceId">Space.</param> /// <param name="gatewayId">Gateway.</param> /// <param name="invoiceId">Invoice.</param> /// <param name="details">Array of parameters.</param> /// <returns>Checkout result object.</returns> public static CheckoutResult CheckOut(string contractId, int invoiceId, string methodName, CheckoutDetails details) { CheckoutResult result = new CheckoutResult(); try { Contract contractInfo = ContractSystem.ContractController.GetContract(contractId); // impersonate ContractSystem.ContractController.ImpersonateAsContractReseller(contractInfo); // TRACE ES.TaskManager.StartTask(TASK_SOURCE, CHECKOUT_TASK, methodName); ES.TaskManager.Write("Start accepting payment for invoice"); ES.TaskManager.WriteParameter("ContractID", contractId); ES.TaskManager.WriteParameter("InvoiceID", invoiceId); // get user details ContractAccount account = ContractSystem.ContractController.GetContractAccountSettings(contractId); // try to load plugin type and throw an exception if type not found IPaymentGatewayProvider provider = (IPaymentGatewayProvider)SystemPluginController.GetContractPaymentMethod( contractInfo, methodName); // add invoice details Invoice invoice = InvoiceController.GetCustomerInvoiceInternally(invoiceId); // append information for the provider details[CheckoutKeys.ContractNumber] = contractId; details[CheckoutKeys.Amount] = invoice.Total.ToString("0.00"); details[CheckoutKeys.InvoiceNumber] = invoice.InvoiceNumber; details[CheckoutKeys.Currency] = invoice.Currency; ES.TaskManager.Write("Submitting payment transaction"); // call checkout routine TransactionResult pgResult = provider.SubmitPaymentTransaction(details); // log provider response SystemPluginController.LogContractPayment(contractInfo, methodName, pgResult.RawResponse); // ERROR if (!pgResult.Succeed) { result.Succeed = false; result.StatusCode = pgResult.StatusCode; // ES.TaskManager.WriteError("Transaction failed"); ES.TaskManager.WriteParameter("StatusCode", result.StatusCode); ES.TaskManager.WriteParameter("RawResponse", pgResult.RawResponse); // EXIT return(result); } // OK ES.TaskManager.Write("Transaction is OK"); // check whether the transaction already exists CustomerPayment tran = StorehouseController.LookupForTransaction(pgResult.TransactionId); // lookup for pending transaction if (tran == null) { // add payment record result.PaymentId = StorehouseController.AddCustomerPayment(contractId, invoice.InvoiceId, pgResult.TransactionId, invoice.Total, invoice.Currency, methodName, pgResult.TransactionStatus); // ERROR if (result.PaymentId < 1) { result.Succeed = false; result.StatusCode = result.PaymentId.ToString(); // ES.TaskManager.WriteError("Could not add customer payment record to the db"); ES.TaskManager.WriteParameter("ResultCode", result.StatusCode); // EXIT return(result); } } // if transaction is already submitted just update it's status if (tran != null) { StorehouseController.UpdateTransactionStatus(tran.PaymentId, pgResult.TransactionStatus); } // OK result.Succeed = true; // ensure user requests to persist his payment details for credit card if (details.Persistent && methodName == PaymentMethod.CREDIT_CARD) { StorehouseController.SetPaymentProfile(contractId, details); } } catch (Exception ex) { result.Succeed = false; result.StatusCode = GENERAL_FAILURE; // ES.TaskManager.WriteError(ex); } finally { ES.TaskManager.CompleteTask(); } // EXIT return(result); }
public static int SendPaymentReceivedNotification(CustomerPayment payment) { ContractAccount account = ContractSystem.ContractController.GetContractAccountSettings(payment.ContractId); Hashtable items = new Hashtable(); items["Payment"] = payment; items["Customer"] = account; return SendSystemNotification(StoreSettings.PAYMENT_RECEIVED, account, items, "HtmlBody", "TextBody"); }