Exemplo n.º 1
0
 public Payment(string identifier, string maskedCardNumber, decimal amount, DateTime expiryDate, string currencyCode, PaymentStatusCode statusCode, DateTime addedDate)
 {
     Identifier       = identifier;
     MaskedCardNumber = maskedCardNumber;
     Amount           = amount;
     ExpiryDate       = expiryDate;
     CurrencyCode     = currencyCode;
     StatusCode       = statusCode;
     AddedDate        = addedDate;
 }
Exemplo n.º 2
0
        public PaymentUpdateResponse PaymentUpdate(string merchantTransactionID, PaymentStatusCode paymentStatusCode)
        {
            if (merchantTransactionID == null)
                throw new ArgumentNullException("merchantTransactionID");

            if (paymentStatusCode == null)
                throw new ArgumentNullException("paymentStatusCode");

            var request = new PaymentUpdateRequest
            {
                MerchantTransactionID = merchantTransactionID,
                PaymentStatusCode = paymentStatusCode
            };
            return PaymentUpdate(request);
        }
Exemplo n.º 3
0
 private void AssertThatPaymentEntityIsCorrect(PaymentEntity actual,
                                               ProcessPaymentRequest expected,
                                               string expectedBankPaymentId,
                                               PaymentStatusCode expectedStatusCode)
 {
     Assert.That(actual, Is.Not.Null);
     Assert.That(actual.PaymentId, Is.Not.EqualTo(Guid.Empty));
     Assert.That(actual.AcquringBankPaymentId, Is.EqualTo(expectedBankPaymentId));
     Assert.That(actual.StatusCode, Is.EqualTo(expectedStatusCode));
     Assert.That(actual.Amount, Is.EqualTo(expected.Amount));
     Assert.That(actual.Currency, Is.EqualTo(expected.Currency));
     Assert.That(actual.CardNumber, Is.EqualTo(expected.CardNumber));
     Assert.That(actual.MaskedCardNumber, Does.StartWith(expected.CardNumber.Substring(0, 4)).And.Contains("****"));
     Assert.That(actual.ExpiryMonthAndDate, Is.EqualTo(expected.ExpiryMonthAndDate));
     Assert.That(actual.Cvv, Is.EqualTo(expected.Cvv));
     Assert.That(actual.MerchantId, Is.EqualTo(expected.MerchantId));
 }
        /// <summary>
        /// Processes the callback from Ogone after the customer has entered credit card information and clicked submit.
        /// </summary>
        /// <param name="payment">The payment.</param>
        public override void ProcessCallback(Payment payment)
        {
            Guard.Against.PaymentNotPendingAuthorization(payment);
            Guard.Against.MissingHttpContext(_webRuntimeInspector);
            Guard.Against.MissingRequestParameter("STATUS");
            Guard.Against.MissingRequestParameter("PAYID");
            Guard.Against.MissingRequestParameter("SHASIGN");

            var         paymentMethod = payment.PaymentMethod;
            HttpContext context       = HttpContext.Current;
            var         computer      = new OgoneSha1Computer();
            var         hashString    = new ProcessCallBackShaSignOut();

            string shaSignOut = paymentMethod.DynamicProperty <string>().ShaSignOut;

            string statusCode    = context.Request["STATUS"];
            string transactionId = context.Request["PAYID"];
            string oGoneShaSign  = context.Request["SHASIGN"].ToUpper();

            string stringToHash = hashString.BuildHashString(context, shaSignOut);
            string shaSign      = computer.ComputeHash(stringToHash).ToUpper();

            if (oGoneShaSign != shaSign)
            {
                throw new SecurityException("Shasigns did not match. Please make sure that 'SHA-OUT Pass phrase' is configured in Ogone and that the same key is configured in Ogone.config.");
            }

            payment["response"] = context.Request.Url.ToString();

            PaymentStatusCode paymentStatus = ConvertAuthorizeResultToPaymentStatus(Convert.ToInt32(statusCode));

            payment.TransactionId = transactionId;
            payment.PaymentStatus = PaymentStatus.Get((int)paymentStatus);

            if (PaymentIsDeclined(payment))
            {
                payment.Save();
            }
            else
            {
                ProcessPaymentRequest(new PaymentRequest(payment.PurchaseOrder, payment));
            }
        }
Exemplo n.º 5
0
        public PaymentUpdateResponse PaymentUpdate(string merchantTransactionID, PaymentStatusCode paymentStatusCode)
        {
            if (merchantTransactionID == null)
            {
                throw new ArgumentNullException("merchantTransactionID");
            }

            if (paymentStatusCode == null)
            {
                throw new ArgumentNullException("paymentStatusCode");
            }

            var request = new PaymentUpdateRequest
            {
                MerchantTransactionID = merchantTransactionID,
                PaymentStatusCode     = paymentStatusCode
            };

            return(PaymentUpdate(request));
        }
        public override Payment CancelPayment(Payment paymentToCancel)
        {
            var  paymentStatus = (PaymentStatusCode)paymentToCancel.PaymentStatus.PaymentStatusId;
            bool statusCode    = false;
            var  status        = string.Empty;

            var globalCollectPaymentStatus = GetOrderStatusFromPayment(paymentToCancel).StatusId;

            if (!IsCancellable(paymentToCancel, globalCollectPaymentStatus))
            {
                return(paymentToCancel);
            }

            if (PaymentQualifiesForCancel(globalCollectPaymentStatus, paymentToCancel))
            {
                statusCode = CancelPaymentInternal(paymentToCancel, out status);
            }

            if (PaymentQualifiesForRefund(globalCollectPaymentStatus, paymentToCancel))
            {
                statusCode = RefundPaymentInternal(paymentToCancel, out status);
            }

            if (PaymentIsAlreadyCancelled(globalCollectPaymentStatus))
            {
                statusCode = true;
                status     = "Payment was already cancelled at Global Collect";
            }

            if (PaymentIsAlreadyRefunded(globalCollectPaymentStatus))
            {
                statusCode = true;
                status     = "Payment was already refunded at Global Collect";
            }

            PaymentStatusCode nextStatus = GetNextStatus(statusCode, paymentStatus);

            SetPaymentStatus(paymentToCancel, nextStatus, status);
            return(paymentToCancel);
        }
        /// <summary>
        /// Processes the payment resonse.
        /// Sets the paymentstatus to either acquired or declined.
        /// </summary>
        /// <param name="payment">The payment request.</param>
        public override void ProcessCallback(Payment payment)
        {
            Guard.Against.PaymentNotPendingAuthorization(payment);

            var    paymentMethod = payment.PaymentMethod;
            string acceptUrl     = paymentMethod.DynamicProperty <string>().AcceptUrl;
            string cancelUrl     = paymentMethod.DynamicProperty <string>().CancelUrl;

            EWayAuthorizationResponse eWayResponse  = VerifyTransactionWithEWay(payment);
            PaymentStatusCode         paymentStatus = eWayResponse.TransactionSuccessful ? PaymentStatusCode.Acquired : PaymentStatusCode.Declined;

            payment.PaymentStatus = PaymentStatus.Get((int)paymentStatus);
            payment.TransactionId = eWayResponse.TransactionNumber;
            payment["AuthCode"]   = eWayResponse.AuthCode;

            if (paymentStatus == PaymentStatusCode.Acquired)
            {
                ProcessPaymentRequest(new PaymentRequest(payment.PurchaseOrder, payment));
            }

            HttpContext.Current.Response.Redirect(paymentStatus == PaymentStatusCode.Acquired
                                                                                                        ? new Uri(_absoluteUrlService.GetAbsoluteUrl(acceptUrl)).AddOrderGuidParameter(payment.PurchaseOrder).ToString()
                                                                : new Uri(_absoluteUrlService.GetAbsoluteUrl(cancelUrl)).AddOrderGuidParameter(payment.PurchaseOrder).ToString());
        }
        private PaymentStatusCode ConvertGlobalCollectOrderStatusToPaymentStatusCode(GlobalCollectOrderStatus status, PaymentStatusCode previous, out string message)
        {
            PaymentStatusCode code;

            switch (status)
            {
            case GlobalCollectOrderStatus.OrderWithAttempt:
                code    = PaymentStatusCode.PendingAuthorization;
                message = "Pending authorization.";
                break;

            case GlobalCollectOrderStatus.OrderWithSuccessfulAttempt:
                code    = PaymentStatusCode.Authorized;
                message = "Payment authorized (Order with successful attempt.";
                break;

            case GlobalCollectOrderStatus.CancelledByMerchant:
                code    = PaymentStatusCode.Declined;
                message = "Cancelled by merchant";
                break;

            case GlobalCollectOrderStatus.RejectedByMerchant:
                code    = PaymentStatusCode.Declined;
                message = "Rejected by merchant";
                break;

            case GlobalCollectOrderStatus.RefundCreated:
                code    = PaymentStatusCode.Refunded;
                message = "Refund created";
                break;

            case GlobalCollectOrderStatus.RefundSuccessful:
                code    = PaymentStatusCode.Refunded;
                message = "Refund successfull";
                break;

            case GlobalCollectOrderStatus.RefundFailed:
                code    = previous;
                message = "Refund successfull";
                break;

            case GlobalCollectOrderStatus.EndedAutomatically:
                code    = PaymentStatusCode.Cancelled;
                message = "Ended automatically";
                break;

            case GlobalCollectOrderStatus.EndedByMerchant:
                code    = PaymentStatusCode.Cancelled;
                message = "Ended by merchant";
                break;

            case GlobalCollectOrderStatus.OrderCreated:
                code    = PaymentStatusCode.PendingAuthorization;
                message = "Order created";
                break;

            case GlobalCollectOrderStatus.OrderSuccessful:
                code    = PaymentStatusCode.Acquired;
                message = "Order successful";
                break;

            case GlobalCollectOrderStatus.OrderOpen:
                code    = PaymentStatusCode.Authorized;
                message = "Order open";
                break;

            default:
                throw new SecurityException("Could not convert status " + status);
            }

            return(code);
        }