コード例 #1
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(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 void ProcessPayment_successfull()
        {
            //arrange
            GatewaySettings settings = new GatewaySettings();

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

            var request = CreatePayRequest();

            //act
            var response = gateway.run(request);

            //assert
            Assert.NotNull(response.getTransactionId());
            Assert.Equal("000", response.getErrorCode());
        }
コード例 #3
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);
        }