public CreatePaymentResponse CreatePayment(CreatePaymentRequest req) { var res = new CreatePaymentResponse(); try { using (var idmClient = new IDMServiceClient()) using (var container = new TransactionModelContainer()) { ValidateCreatePaymentRequest(idmClient, req); var payment = new Payment( req.CreateBy, req.CustomerIDMPartyID, req.CustomerName, req.CustomerAddress, req.PaymentItems.CreatePaymentItems() ); var grandTotal = payment.GrandTotal(); var credits = container.CustomerCredits.Where(x => x.CustomerIdmPartyId == req.CustomerIDMPartyID && x.IsUsedOrRefund == false).ToList(); var credit = credits.GetCustomerCredit(grandTotal); foreach (var c in credit) payment.AddPaymentItem(PaymentItem.CreateCustomerCredit(c.Id, c.Amount)); CustomerCredit.UpdateCustomerCredit(credit); container.Payments.AddObject(payment); container.SaveChanges(); res.SetPaymentResponse(payment); res.Succeed(); } } catch (Exception x) { res.Fail(x); CreateLog(req, x); } return res; }
public void TestCreatePayment() { try { using (TransactionScope scope = new TransactionScope()) { var service = new TransactionServiceImpl.TransactionService(); CreatePaymentRequest req = new CreatePaymentRequest(); req.CreateBy = "TEST 2"; req.CustomerIDMPartyID = 912; req.CustomerName = "TEST 2"; req.CustomerAddress = "44/55"; CreatePaymentItemRequest item = new CreatePaymentItemRequest(); //item.ServiceCode = "1"; item.ItemDescription = "Subscription Fee"; item.Quantity = 1; item.UnitAmount = 3000; item.VatPercent = 7; item.WithholdingTaxPercent = 3; item.ServiceIsRevenue = true; item.IsLegalPerson = false; req.PaymentItems = new CreatePaymentItemRequest[1]; req.PaymentItems[0] = item; service.CreatePayment(req); bool err = true; if (err) throw new Exception("error"); scope.Complete(); } } catch (Exception ex) { } }
private void ValidateCreatePaymentRequest(IDMServiceClient client, CreatePaymentRequest req) { if (req == null) throw new ApplicationException("MISSING_REQUIRED_PARAMETER(S)"); if (string.IsNullOrEmpty(req.CreateBy)) throw new ApplicationException("EMPTY_OR_NULL_CREATED_BY"); if (string.IsNullOrEmpty(req.CustomerName)) throw new ApplicationException("EMPTY_OR_NULL_CUSTOMERNAME"); if (string.IsNullOrEmpty(req.CustomerAddress)) throw new ApplicationException("EMPTY_OR_NULL_CUSTOMERADDRESS"); if (req.PaymentItems == null || req.PaymentItems.Length < 1) throw new ApplicationException("AT_LEAST_ONE_PAYMENT_ITEM_IS_REQUIRED"); }
private void CreateLog(CreatePaymentRequest req, Exception ex) { ErrorLog.Log(req.CustomerName, ex, SystemError.TransactionService); }