public override ProcessPaymentResult ProcessPayment(ProcessPaymentEvaluationContext context)
        {
            var retVal = new ProcessPaymentResult();

            GatewaySettings settings = new GatewaySettings();

            settings.setCredentials(ProfileId, ProfileKey)
            //.setVerbose(true)
            .setHostUrl(GatewaySettings.URL_CERT);
            Gateway gateway = new Gateway(settings);

            GatewayRequest request = new GatewayRequest(GatewayRequest.TransactionType.SALE);

            if (string.IsNullOrEmpty(context.Payment.OuterId))
            {
                request.setCardData(context.BankCardInfo.BankCardNumber,
                                    context.BankCardInfo.BankCardMonth.ToString() + context.BankCardInfo.BankCardYear);

                request.setCurrencyCode(context.Payment.Currency);

                if (context.Payment.BillingAddress != null)
                {
                    request.setBillingAddress(context.Payment.BillingAddress.ToString(), context.Payment.BillingAddress.Zip);
                }
            }
            else
            {
                request.setTokenData(context.Payment.OuterId, string.Empty);
            }
            request.setAmount(context.Order.Sum.ToString(CultureInfo.InvariantCulture));
            GatewayResponse response = gateway.run(request);

            var transactionId = response.getTransactionId();

            var errorCode = response.getErrorCode();

            if (errorCode.Equals("000"))
            {
                context.Payment.AuthorizedDate = DateTime.UtcNow;
                context.Payment.CapturedDate   = DateTime.UtcNow;
                retVal.OuterId          = context.Payment.OuterId = transactionId;
                retVal.NewPaymentStatus = context.Payment.PaymentStatus = PaymentStatus.Paid;
                retVal.IsSuccess        = context.Payment.IsApproved = true;
            }
            else
            {
                retVal.NewPaymentStatus = PaymentStatus.Voided;
                retVal.Error            = string.Format("MeS error {0}", errorCode);
            }

            return(retVal);
        }
Пример #2
0
        public override ProcessPaymentResult ProcessPayment(ProcessPaymentEvaluationContext context)
        {
            var retVal = new ProcessPaymentResult();

            GatewaySettings settings = new GatewaySettings();

            settings.setCredentials(ProfileId, ProfileKey)
            .setVerbose(true)
            .setHostUrl(GatewaySettings.URL_CERT);
            Gateway gateway = new Gateway(settings);

            GatewayRequest request = new GatewayRequest(GatewayRequest.TransactionType.SALE);

            if (string.IsNullOrEmpty(context.Payment.OuterId))
            {
                request.setCardData("4012888812348882", "1216");
            }
            else
            {
                request.setTokenData(context.Payment.OuterId, string.Empty);
            }
            request.setAmount("1.03");
            GatewayResponse response = gateway.run(request);

            var tranId = response.getTransactionId();

            var errorCode = response.getErrorCode();

            if (errorCode.Equals("000"))
            {
                retVal.OuterId          = tranId;
                retVal.IsSuccess        = true;
                retVal.NewPaymentStatus = PaymentStatus.Pending;                 //maybe
            }
            else
            {
                retVal.NewPaymentStatus = PaymentStatus.Voided;
                retVal.Error            = string.Format("Mes error {0}", errorCode);
            }

            return(retVal);
        }