private static PaymentNotice createPaymentNotice(FormCollection formCollection)
 {
     log.Info(ToJSON(formCollection));
     var paymentNotice = new PaymentNotice();
     var paymentRef = formCollection["merchantReference"];
     paymentNotice.success = (formCollection["success"] == "true");
     paymentNotice.reason = formCollection["reason"];
     paymentNotice.paymentRef = paymentRef;
     paymentNotice.type = formCollection["eventCode"];
     paymentNotice.transactionId = (formCollection["eventCode"] == "AUTHORISATION") ? formCollection["pspReference"] : formCollection["originalReference"];
     return paymentNotice;
 }
        private static PaymentNotice buildPaymentNotice(PaymentResult paymentresult)
        {
            var transResultCode = paymentresult.resultCode.Replace("Authorised", "AUTHORISATION").Replace("Refused", "REFUSED");
            var paymentNotice = new PaymentNotice
                                    {
                                        paymentRef = paymentRef,
                                        reason = paymentresult.refusalReason,
                                        transactionId = paymentresult.pspReference,
                                        type = transResultCode,
                                        success = true
                                    };

            return paymentNotice;
        }
 public static void save(PaymentNotice paymentNotice)
 {
     try
     {
         var orm = new Orm();
         var result = orm.execObject<Result>(paymentNotice, "api.user_add_payment_notice");
         if (result.errorMessage != null)
             throw new DivideByZeroException();
     }
     catch (DivideByZeroException exp)
     {
         log.Error("Error saving payment notice to DB" + exp.Message);
         throw;
     }
 }
        public string paymentResult(AdyenResult adyenResult)
        {
            try
            {
                //here we map the fields
                var paymentNotice = new PaymentNotice
                    {
                        success = true,
                        paymentRef = adyenResult.merchantReference,
                        type = (adyenResult.authResult == "A") ? "AUTHORISATION" : "REFUSED",
                        transactionId = adyenResult.pspReference
                    };

                //then we create thepayment notice
                CreatePaymentNotice.save(paymentNotice);

                //then we result a payment status
                result.PaymentStatus = new PaymentStatus
                    {
                        paymentRef = adyenResult.merchantReference,
                        success = (adyenResult.authResult == "A"),

                    };

                if (result.PaymentStatus.success)
                {

                   //pay.paymentRef, pay.amount, pay.currency, pay.shopperEmail, pay.accountHolderName
                    var paramPayment = new Payment { paymentRef = adyenResult.merchantReference };
                    result.Payment = orm.execObject<Result>(paramPayment, "api.user_payment_get").Payment;

                    result.Payment.sendReceiptEmail();
                }
             }
            catch (Exception exp)
            {
                errorResult(exp);
            }
            return formattedResult(result);
        }