Пример #1
0
        private string ConvertResponse(JsonDoc request, Transaction trans)
        {
            var merchantId = request.GetValue <string>("MERCHANT_ID");
            var account    = request.GetValue <string>("ACCOUNT");

            // begin building response
            var response = new JsonDoc(JsonEncoders.Base64Encoder);

            response.Set("MERCHANT_ID", merchantId);
            response.Set("ACCOUNT", request.GetValue <string>("ACCOUNT"));
            response.Set("ORDER_ID", trans.OrderId);
            response.Set("TIMESTAMP", trans.Timestamp);
            response.Set("RESULT", trans.ResponseCode);
            response.Set("PASREF", trans.TransactionId);
            response.Set("AUTHCODE", trans.AuthorizationCode);
            response.Set("AVSPOSTCODERESULT", trans.AvsResponseCode);
            response.Set("CVNRESULT", trans.CvnResponseCode);
            response.Set("HPP_LANG", request.GetValue <string>("HPP_LANG"));
            response.Set("SHIPPING_CODE", request.GetValue <string>("SHIPPING_CODE"));
            response.Set("SHIPPING_CO", request.GetValue <string>("SHIPPING_CO"));
            response.Set("BILLING_CODE", request.GetValue <string>("BILLING_CODE"));
            response.Set("BILLING_CO", request.GetValue <string>("BILLING_CO"));
            response.Set("ECI", request.GetValue <string>("ECI"));
            response.Set("CAVV", request.GetValue <string>("CAVV"));
            response.Set("XID", request.GetValue <string>("XID"));
            response.Set("MERCHANT_RESPONSE_URL", request.GetValue <string>("MERCHANT_RESPONSE_URL"));
            response.Set("CARD_PAYMENT_BUTTON", request.GetValue <string>("CARD_PAYMENT_BUTTON"));
            response.Set("MESSAGE", trans.ResponseMessage);
            response.Set("AMOUNT", trans.AuthorizedAmount);
            response.Set("SHA1HASH", GenerationUtils.GenerateHash(_sharedSecret, trans.Timestamp, merchantId, trans.OrderId, trans.ResponseCode, trans.ResponseMessage, trans.TransactionId, trans.AuthorizationCode));
            response.Set("DCC_INFO_REQUST", request.GetValue <string>("DCC_INFO"));
            response.Set("HPP_FRAUDFILTER_MODE", request.GetValue <string>("HPP_FRAUDFILTER_MODE"));
            if (trans?.FraudResponse?.Rules != null)
            {
                response.Set("HPP_FRAUDFILTER_RESULT", trans.FraudResponse?.Result);

                foreach (var rule in trans.FraudResponse.Rules)
                {
                    response.Set("HPP_FRAUDFILTER_RULE_" + rule.Id, rule.Action);
                }
            }
            if (trans?.AlternativePaymentResponse != null)
            {
                AlternativePaymentResponse alternativePaymentResponse = trans.AlternativePaymentResponse;
                response.Set("HPP_CUSTOMER_FIRSTNAME", request.GetValue <string>("HPP_CUSTOMER_FIRSTNAME"));
                response.Set("HPP_CUSTOMER_LASTNAME", request.GetValue <string>("HPP_CUSTOMER_LASTNAME"));
                response.Set("HPP_CUSTOMER_COUNTRY", request.GetValue <string>("HPP_CUSTOMER_COUNTRY"));
                response.Set("PAYMENTMETHOD", alternativePaymentResponse.ProviderName);
                response.Set("PAYMENTPURPOSE", alternativePaymentResponse.PaymentPurpose);
                response.Set("HPP_CUSTOMER_BANK_ACCOUNT", alternativePaymentResponse.BankAccount);
            }

            return(response.ToString());
        }
Пример #2
0
        /// <summary>
        /// Map response for an APM transaction
        /// </summary>
        /// <param name="response"></param>
        /// <returns>Transaction</returns>
        public static Transaction MapResponseAPM(string rawResponse)
        {
            var apm         = new AlternativePaymentResponse();
            var transaction = MapResponse(rawResponse);

            JsonDoc json = JsonDoc.Parse(rawResponse);

            var paymentMethodApm = json.Get("payment_method")?.Get("apm");

            apm.RedirectUrl            = json.Get("payment_method")?.GetValue <string>("redirect_url");
            apm.ProviderName           = paymentMethodApm?.GetValue <string>("provider");
            apm.Ack                    = paymentMethodApm?.GetValue <string>("ack");
            apm.SessionToken           = paymentMethodApm?.GetValue <string>("session_token");
            apm.CorrelationReference   = paymentMethodApm?.GetValue <string>("correlation_reference");
            apm.VersionReference       = paymentMethodApm?.GetValue <string>("version_reference");
            apm.BuildReference         = paymentMethodApm?.GetValue <string>("build_reference");
            apm.TimeCreatedReference   = paymentMethodApm?.GetValue <DateTime?>("time_created_reference", DateConverter);
            apm.TransactionReference   = paymentMethodApm?.GetValue <string>("transaction_reference");
            apm.SecureAccountReference = paymentMethodApm?.GetValue <string>("secure_account_reference");
            apm.ReasonCode             = paymentMethodApm?.GetValue <string>("reason_code");
            apm.PendingReason          = paymentMethodApm?.GetValue <string>("pending_reason");
            apm.GrossAmount            = paymentMethodApm?.GetValue <string>("gross_amount")?.ToAmount();
            apm.PaymentTimeReference   = paymentMethodApm?.GetValue <DateTime?>("payment_time_reference", DateConverter);
            apm.PaymentType            = paymentMethodApm?.GetValue <string>("payment_type");
            apm.PaymentStatus          = paymentMethodApm?.GetValue <string>("payment_status");
            apm.Type                   = paymentMethodApm?.GetValue <string>("type");
            apm.ProtectionEligibility  = paymentMethodApm?.GetValue <string>("protection_eligibilty");
            apm.FeeAmount              = paymentMethodApm?.GetValue <string>("fee_amount")?.ToAmount();

            var authorization = json.Get("payment_method")?.Get("authorization");

            apm.AuthStatus = authorization?.GetValue <string>("status");
            apm.AuthAmount = authorization?.GetValue <string>("amount")?.ToAmount();
            apm.AuthAck    = authorization?.GetValue <string>("ack");
            apm.AuthCorrelationReference      = authorization?.GetValue <string>("correlation_reference");
            apm.AuthVersionReference          = authorization?.GetValue <string>("version_reference");
            apm.AuthBuildReference            = authorization?.GetValue <string>("build_reference");
            apm.AuthPendingReason             = authorization?.GetValue <string>("pending_reason");
            apm.AuthProtectionEligibility     = authorization?.GetValue <string>("protection_eligibilty");
            apm.AuthProtectionEligibilityType = authorization?.GetValue <string>("protection_eligibilty_type");
            apm.AuthReference = authorization?.GetValue <string>("reference");

            transaction.AlternativePaymentResponse = apm;

            return(transaction);
        }
Пример #3
0
        public static TransactionSummary MapTransactionSummary(JsonDoc doc)
        {
            var summary = new TransactionSummary {
                TransactionId         = doc.GetValue <string>("id"),
                TransactionDate       = doc.GetValue <DateTime?>("time_created", DateConverter),
                TransactionStatus     = doc.GetValue <string>("status"),
                TransactionType       = doc.GetValue <string>("type"),
                Channel               = doc.GetValue <string>("channel"),
                Amount                = doc.GetValue <string>("amount").ToAmount(),
                Currency              = doc.GetValue <string>("currency"),
                ReferenceNumber       = doc.GetValue <string>("reference"),
                ClientTransactionId   = doc.GetValue <string>("reference"),
                TransactionLocalDate  = doc.GetValue <DateTime?>("time_created_reference", DateConverter),
                BatchSequenceNumber   = doc.GetValue <string>("batch_id"),
                Country               = doc.GetValue <string>("country"),
                OriginalTransactionId = doc.GetValue <string>("parent_resource_id"),
                DepositReference      = doc.GetValue <string>("deposit_id"),
                BatchCloseDate        = doc.GetValue <DateTime?>("batch_time_created", DateConverter),
                DepositDate           = doc.GetValue <DateTime?>("deposit_time_created", DateConverter),

                MerchantId        = doc.Get("system")?.GetValue <string>("mid"),
                MerchantHierarchy = doc.Get("system")?.GetValue <string>("hierarchy"),
                MerchantName      = doc.Get("system")?.GetValue <string>("name"),
                MerchantDbaName   = doc.Get("system")?.GetValue <string>("dba"),
            };

            if (doc.Has("payment_method"))
            {
                JsonDoc paymentMethod = doc.Get("payment_method");
                summary.GatewayResponseMessage = paymentMethod?.GetValue <string>("message");
                summary.EntryMode      = paymentMethod?.GetValue <string>("entry_mode");
                summary.CardHolderName = paymentMethod?.GetValue <string>("name");

                if (paymentMethod.Has("card"))
                {
                    JsonDoc card = paymentMethod?.Get("card");
                    summary.CardType               = card?.GetValue <string>("brand");
                    summary.AuthCode               = card?.GetValue <string>("authcode");
                    summary.BrandReference         = card?.GetValue <string>("brand_reference");
                    summary.AquirerReferenceNumber = card?.GetValue <string>("arn");
                    summary.MaskedCardNumber       = card?.GetValue <string>("masked_number_first6last4");
                    summary.PaymentType            = EnumConverter.GetMapping(Target.GP_API, PaymentMethodName.Card);
                }
                else if (paymentMethod.Has("digital_wallet"))
                {
                    JsonDoc digitalWallet = paymentMethod?.Get("digital_wallet");
                    summary.MaskedCardNumber = digitalWallet?.GetValue <string>("masked_token_first6last4");
                    summary.PaymentType      = EnumConverter.GetMapping(Target.GP_API, PaymentMethodName.DigitalWallet);
                }
                else if (paymentMethod.Has("bank_transfer"))
                {
                    JsonDoc bankTransfer = paymentMethod?.Get("bank_transfer");
                    summary.AccountNumberLast4 = bankTransfer?.GetValue <string>("masked_account_number_last4");
                    summary.AccountType        = bankTransfer?.GetValue <string>("account_type");
                    summary.PaymentType        = EnumConverter.GetMapping(Target.GP_API, PaymentMethodName.BankTransfer);
                }
                else if (paymentMethod.Has("apm"))
                {
                    JsonDoc apm = paymentMethod?.Get("apm");
                    var     alternativePaymentResponse = new AlternativePaymentResponse();
                    alternativePaymentResponse.RedirectUrl       = apm?.GetValue <string>("redirect_url");
                    alternativePaymentResponse.ProviderName      = apm?.GetValue <string>("provider");
                    alternativePaymentResponse.ProviderReference = apm?.GetValue <string>("provider_reference");
                    summary.AlternativePaymentResponse           = alternativePaymentResponse;
                    summary.PaymentType = EnumConverter.GetMapping(Target.GP_API, PaymentMethodName.APM);
                }
            }
            return(summary);
        }