コード例 #1
0
        public async Task <Payment> AuthorizePayment(
            OrderCloudIntegrationsCreditCardPayment payment,
            string userToken,
            string merchantID
            )
        {
            Require.That((payment.CreditCardID != null) || (payment.CreditCardDetails != null),
                         new ErrorCode("CreditCard.CreditCardAuth", 400, "Request must include either CreditCardDetails or CreditCardID"));

            var cc = await GetMeCardDetails(payment, userToken);

            Require.That(payment.IsValidCvv(cc), new ErrorCode("CreditCardAuth.InvalidCvv", 400, "CVV is required for Credit Card Payment"));
            Require.That(cc.Token != null, new ErrorCode("CreditCardAuth.InvalidToken", 400, "Credit card must have valid authorization token"));
            Require.That(cc.xp.CCBillingAddress != null, new ErrorCode("Invalid Bill Address", 400, "Credit card must have a billing address"));

            var orderWorksheet = await _oc.IntegrationEvents.GetWorksheetAsync <HSOrderWorksheet>(OrderDirection.Incoming, payment.OrderID);

            var order = orderWorksheet.Order;

            Require.That(!order.IsSubmitted, new ErrorCode("CreditCardAuth.AlreadySubmitted", 400, "Order has already been submitted"));

            var ccAmount = orderWorksheet.Order.Total;

            var ocPaymentsList = (await _oc.Payments.ListAsync <HSPayment>(OrderDirection.Incoming, payment.OrderID, filters: "Type=CreditCard"));
            var ocPayments     = ocPaymentsList.Items;
            var ocPayment      = ocPayments.Any() ? ocPayments[0] : null;

            if (ocPayment == null)
            {
                throw new CatalystBaseException("Payment.MissingCreditCardPayment", 400, "Order is missing credit card payment");
            }
            try
            {
                if (ocPayment?.Accepted == true)
                {
                    if (ocPayment.Amount == ccAmount)
                    {
                        return(ocPayment);
                    }
                    else
                    {
                        await VoidTransactionAsync(ocPayment, order, userToken);
                    }
                }
                var call = await _cardConnect.AuthWithoutCapture(CardConnectMapper.Map(cc, order, payment, merchantID, ccAmount));

                ocPayment = await _oc.Payments.PatchAsync <HSPayment>(OrderDirection.Incoming, order.ID, ocPayment.ID, new PartialPayment { Accepted = true, Amount = ccAmount });

                return(await _oc.Payments.CreateTransactionAsync(OrderDirection.Incoming, order.ID, ocPayment.ID, CardConnectMapper.Map(ocPayment, call)));
            }
            catch (CreditCardAuthorizationException ex)
            {
                ocPayment = await _oc.Payments.PatchAsync <HSPayment>(OrderDirection.Incoming, order.ID, ocPayment.ID, new PartialPayment { Accepted = false, Amount = ccAmount });

                await _oc.Payments.CreateTransactionAsync(OrderDirection.Incoming, order.ID, ocPayment.ID, CardConnectMapper.Map(ocPayment, ex.Response));

                throw new CatalystBaseException($"CreditCardAuth.{ex.ApiError.ErrorCode}", 400, ex.ApiError.Message, ex.Response);
            }
        }
コード例 #2
0
 private async Task <CardConnectBuyerCreditCard> GetMeCardDetails(OrderCloudIntegrationsCreditCardPayment payment, string userToken)
 {
     if (payment.CreditCardID != null)
     {
         return(await _oc.Me.GetCreditCardAsync <CardConnectBuyerCreditCard>(payment.CreditCardID, userToken));
     }
     return(await MeTokenize(payment.CreditCardDetails, userToken));
 }
コード例 #3
0
 public static bool IsValidCvv(this OrderCloudIntegrationsCreditCardPayment payment, BuyerCreditCard cc)
 {
     // if credit card is direct without using a saved card then consider it a ME card and should enforce CVV
     // saved credit cards for ME just require CVV
     return((payment.CreditCardDetails == null || payment.CVV != null) && (!cc.Editable || payment.CVV != null));
 }
コード例 #4
0
        public static CardConnectAuthorizationRequest Map(BuyerCreditCard card, Order order, OrderCloudIntegrationsCreditCardPayment payment, string merchantID, decimal amount)
        {
            var address = card.xp.CCBillingAddress;
            var req     = new CardConnectAuthorizationRequest()
            {
                name     = $"{card.CardholderName}",
                account  = card.Token,
                address  = address.Street1,
                amount   = amount.ToString(),
                city     = address.City,
                country  = address.Country,
                currency = payment.Currency,
                cvv2     = payment.CVV,
                expiry   = $"{card.ExpirationDate.Value:MMyyyy}",
                merchid  = merchantID,
                orderid  = order.ID,
                postal   = address.Zip,
                region   = address.State
            };

            return(req);
        }