示例#1
0
    protected void processPayment(ElectronicPaymentManifest payment)
    {
        decimal sumOfItems  = targetPayment.LineItems.Sum(x => x.Total);
        decimal overpayment = targetPayment.Total - sumOfItems;

        // add the overpayment
        if (overpayment > 0)
        {
            // not allow
            throw new ConciergeClientException(MemberSuite.SDK.Concierge.ConciergeErrorCode.IllegalOperation, "The sum of the invoice payments is less than the total payment amount. Please make sure all of the money in your payment is applied to invoices. ");
            //targetPayment.LineItems.Add(new msPaymentLineItem
            //                              {Amount = overpayment, Type = PaymentLineItemType.OverPayment});
        }

        string antiDupeKey = (string)Request["AntiDupeKey"];

        using (var api = GetServiceAPIProxy())
        {
            var merchantAccount = DetermineMerchantAccount();
            targetPayment.CashAccount = merchantAccount;
            var r = api.ProcessPayment(targetPayment, payment, null);
            if (!r.Success)
            {
                throw new ConciergeClientException(MemberSuite.SDK.Concierge.ConciergeErrorCode.GeneralException, r.FirstErrorMessage);
            }
            PaymentProcessorResponse resp = r.ResultValue;

            if (!resp.Success)
            {
                // ok, we're throwing an exception
                throw new ConciergeClientException(
                          MemberSuite.SDK.Concierge.ConciergeErrorCode.CreditCardAuthorizationFailed,
                          "Unable to process payment: [{0}] - {1}", resp.GatewayResponseReasonCode, resp.GatewayResponseReasonText);
            }

            targetPayment = LoadObjectFromAPI <msPayment>(resp.PaymentID);


            // now, send a confirmation email
            api.SendTransactionalEmail(EmailTemplates.Financial.Payment, targetPayment.ID, ConciergeAPI.CurrentUser.EmailAddress);
        }
    }
        public void MapsCorrectly_PaymentProcessorResponse()
        {
            var gatewayRequest = GetTestGatewayRequest();
            var response       = new PaymentProcessorResponse
            {
                GatewayId                 = gatewayRequest.GatewayId,
                FailureReason             = "funds not sufficient",
                IsSuccess                 = false,
                PaymentProcessorReference = Guid.NewGuid().ToString()
            };

            var result = PaymentProcessorMapper.MapResponse(response, gatewayRequest);

            Check.That(response).IsNotNull();
            Check.That(result.TruncatedCardNumber).IsNotEqualTo(gatewayRequest.LongNumber);
            Check.That(result.GatewayId).Equals(gatewayRequest.GatewayId);
            Check.That(result.PaymentAmount).Equals(gatewayRequest.PaymentAmount);
            Check.That(result.PaymentCurrency).Equals(gatewayRequest.PaymentCurrency);
            Check.That(result.PaymentProcessorId).Equals(response.PaymentProcessorReference);
            Check.That(result.MerchantId).Equals(gatewayRequest.MerchantId);
            Check.That(result.MerchantReferenceNumber).Equals(gatewayRequest.MerchantReferenceNumber);
        }