internal BaseTableServiceResponse(string json)
        {
            if (string.IsNullOrEmpty(json))
            {
                return;
            }

            var response = JsonDoc.Parse(json);

            ResponseCode = NormalizeResponse(response.GetValue <string>("code"));
            ResponseText = response.GetValue <string>("codeMsg");
            Class        = response.GetValue <string>("class");
            Action       = response.GetValue <string>("action");

            if (!ResponseCode.Equals("00"))
            {
                throw new MessageException(ResponseText);
            }

            // map response from the data rows
            if (response.Has("data"))
            {
                var data = response.Get("data");
                if (data.Has("row"))
                {
                    var row = data.Get("row");
                    MapResponse(row ?? data);
                }
            }
        }
Exemplo n.º 2
0
        private string GetResponseMessageType(byte[] response)
        {
            var jsonObject = System.Text.Encoding.UTF8.GetString(TrimResponse(response));
            var jsonDoc    = JsonDoc.Parse(jsonObject);

            return(jsonDoc.GetValue <string>("message"));
        }
Exemplo n.º 3
0
        public void MapResponseTest()
        {
            // Arrange
            string rawJson = "{\"id\":\"TRN_BHZ1whvNJnMvB6dPwf3znwWTsPjCn0\",\"time_created\":\"2020-12-04T12:46:05.235Z\",\"type\":\"SALE\",\"status\":\"PREAUTHORIZED\",\"channel\":\"CNP\",\"capture_mode\":\"LATER\",\"amount\":\"1400\",\"currency\":\"USD\",\"country\":\"US\",\"merchant_id\":\"MER_c4c0df11039c48a9b63701adeaa296c3\",\"merchant_name\":\"Sandbox_merchant_2\",\"account_id\":\"TRA_6716058969854a48b33347043ff8225f\",\"account_name\":\"Transaction_Processing\",\"reference\":\"15fbcdd9-8626-4e29-aae8-050f823f995f\",\"payment_method\":{\"result\":\"00\",\"message\":\"[ test system ] AUTHORISED\",\"entry_mode\":\"ECOM\",\"card\":{\"brand\":\"VISA\",\"masked_number_last4\":\"XXXXXXXXXXXX5262\",\"authcode\":\"12345\",\"brand_reference\":\"PSkAnccWLNMTcRmm\",\"brand_time_created\":\"\",\"cvv_result\":\"MATCHED\"}},\"batch_id\":\"\",\"action\":{\"id\":\"ACT_BHZ1whvNJnMvB6dPwf3znwWTsPjCn0\",\"type\":\"PREAUTHORIZE\",\"time_created\":\"2020-12-04T12:46:05.235Z\",\"result_code\":\"SUCCESS\",\"app_id\":\"Uyq6PzRbkorv2D4RQGlldEtunEeGNZll\",\"app_name\":\"sample_app_CERT\"}}";

            // Act
            Transaction transaction = GpApiMapping.MapResponse(rawJson);

            JsonDoc doc = JsonDoc.Parse(rawJson);

            // Assert
            Assert.AreEqual(doc.GetValue <string>("id"), transaction.TransactionId);
            Assert.AreEqual(doc.GetValue <string>("amount").ToAmount(), transaction.BalanceAmount);
            Assert.AreEqual(doc.GetValue <string>("time_created"), transaction.Timestamp);
            Assert.AreEqual(doc.GetValue <string>("status"), transaction.ResponseMessage);
            Assert.AreEqual(doc.GetValue <string>("reference"), transaction.ReferenceNumber);
            Assert.AreEqual(doc.GetValue <string>("batch_id"), transaction.BatchSummary?.SequenceNumber);
            Assert.AreEqual(doc.Get("action").GetValue <string>("result_code"), transaction.ResponseCode);
            Assert.AreEqual(doc.GetValue <string>("id"), transaction.Token);

            if (doc.Has("payment_method"))
            {
                Assert.AreEqual(doc.Get("payment_method")?.GetValue <string>("result"), transaction.AuthorizationCode);
                Assert.AreEqual(doc.Get("payment_method")?.Get("card")?.GetValue <string>("brand"), transaction.CardType);
                Assert.AreEqual(doc.Get("payment_method")?.Get("card")?.GetValue <string>("masked_number_last4"), transaction.CardLast4);
            }

            if (doc.Has("card"))
            {
                Assert.AreEqual(doc.Get("card")?.GetValue <string>("number"), transaction.CardNumber);
                Assert.AreEqual(doc.Get("card")?.GetValue <string>("brand"), transaction.CardType);
                Assert.AreEqual(doc.Get("card")?.GetValue <int>("expiry_month"), transaction.CardExpMonth);
                Assert.AreEqual(doc.Get("card")?.GetValue <int>("expiry_year"), transaction.CardExpYear);
            }
        }
Exemplo n.º 4
0
        public void MapDisputeSummaryTest_NullDate()
        {
            // Arrange
            string rawJson = "{\"id\":\"DIS_SAND_abcd1234\",\"time_created\":\"\",\"merchant_id\":\"MER_62251730c5574bbcb268191b5f315de8\",\"merchant_name\":\"TEST MERCHANT\",\"account_id\":\"DIA_882c832d13e04185bb6e213d6303ed98\",\"account_name\":\"testdispute\",\"status\":\"WITH_MERCHANT\",\"status_time_created\":\"\",\"stage\":\"RETRIEVAL\",\"stage_time_created\":\"\",\"amount\":\"1000\",\"currency\":\"USD\",\"payer_amount\":\"1000\",\"payer_currency\":\"USD\",\"merchant_amount\":\"1000\",\"merchant_currency\":\"USD\",\"reason_code\":\"104\",\"reason_description\":\"Other Fraud-Card Absent Environment\",\"time_to_respond_by\":\"\",\"result\":\"PENDING\",\"investigator_comment\":\"WITH_MERCHANT RETRIEVAL PENDING 1000 USD 1000 USD\",\"system\":{\"mid\":\"11112334\",\"tid\":\"22229876\",\"hierarchy\":\"000-00-000-000-000\",\"name\":\"MERCHANT ABC INC.\",\"dba\":\"MERCHANT XYZ INC.\"},\"last_adjustment_amount\":\"\",\"last_adjustment_currency\":\"\",\"last_adjustment_funding\":\"\",\"last_adjustment_time_created\":\"\",\"net_financial_amount\":\"\",\"net_financial_currency\":\"\",\"net_financial_funding\":\"\",\"payment_method_provider\":[{\"comment\":\"issuer comments 34523\",\"reference\":\"issuer-reference-0001\",\"documents\":[{\"id\":\"DOC_MyEvidence_234234AVCDE-1\"}]}],\"transaction\":{\"time_created\":\"\",\"type\":\"SALE\",\"amount\":\"1000\",\"currency\":\"USD\",\"reference\":\"my-trans-AAA1\",\"remarks\":\"my-trans-AAA1\",\"payment_method\":{\"card\":{\"number\":\"424242xxxxxx4242\",\"arn\":\"834523482349123\",\"brand\":\"VISA\",\"authcode\":\"234AB\",\"brand_reference\":\"23423421342323A\"}}},\"documents\":[],\"action\":{\"id\":\"ACT_5blBTHnIs4aOCIvGwG7KizYUpsGI0g\",\"type\":\"DISPUTE_SINGLE\",\"time_created\":\"\",\"result_code\":\"SUCCESS\",\"app_id\":\"JF2GQpeCrOivkBGsTRiqkpkdKp67Gxi0\",\"app_name\":\"test_app\"}}";

            JsonDoc doc = JsonDoc.Parse(rawJson);

            // Act
            DisputeSummary dispute = GpApiMapping.MapDisputeSummary(doc);

            // Assert
            Assert.AreEqual(doc.GetValue <string>("id"), dispute.CaseId);
            Assert.IsNull(dispute.CaseIdTime);
            Assert.AreEqual(doc.GetValue <string>("status"), dispute.CaseStatus);
            Assert.AreEqual(doc.GetValue <string>("stage"), dispute.CaseStage);
            Assert.AreEqual(doc.GetValue <string>("amount").ToAmount(), dispute.CaseAmount);
            Assert.AreEqual(doc.GetValue <string>("currency"), dispute.CaseCurrency);
            Assert.AreEqual(doc.GetValue <string>("reason_code"), dispute.ReasonCode);
            Assert.AreEqual(doc.GetValue <string>("reason_description"), dispute.Reason);
            Assert.IsNull(dispute.RespondByDate);
            Assert.AreEqual(doc.GetValue <string>("result"), dispute.Result);
            Assert.AreEqual(doc.Get("system")?.GetValue <string>("mid"), dispute.CaseMerchantId);
            Assert.AreEqual(doc.Get("system")?.GetValue <string>("tid"), dispute.CaseTerminalId);
            Assert.AreEqual(doc.Get("system")?.GetValue <string>("hierarchy"), dispute.MerchantHierarchy);
            Assert.AreEqual(doc.Get("system")?.GetValue <string>("name"), dispute.MerchantName);
            Assert.AreEqual(doc.Get("system")?.GetValue <string>("dba"), dispute.MerchantDbaName);
            Assert.AreEqual(doc.GetValue <string>("last_adjustment_amount").ToAmount(), dispute.LastAdjustmentAmount);
            Assert.AreEqual(doc.GetValue <string>("last_adjustment_currency"), dispute.LastAdjustmentCurrency);
            Assert.AreEqual(doc.GetValue <string>("last_adjustment_funding"), dispute.LastAdjustmentFunding);
            Assert.AreEqual(doc.Get("payment_method")?.Get("card")?.GetValue <string>("number"), dispute.TransactionMaskedCardNumber);
            Assert.AreEqual(doc.Get("payment_method")?.Get("card")?.GetValue <string>("arn"), dispute.TransactionARN);
            Assert.AreEqual(doc.Get("payment_method")?.Get("card")?.GetValue <string>("brand"), dispute.TransactionCardType);
        }
Exemplo n.º 5
0
        public void MapActionSummaryTest()
        {
            // Arrange
            string rawJson = "{\"id\":\"ACT_PJiFWTaNcLW8aVBo2fA8E5Dqd8ZyrH\",\"type\":\"CREATE_TOKEN\",\"time_created\":\"2021-03-24T02:02:27.158Z\",\"resource\":\"ACCESS_TOKENS\",\"resource_request_url\":\"http://*****:*****@globalpay.com\",\"merchant_id\":\"MER_c4c0df11039c48a9b63701adeaa296c3\",\"merchant_name\":\"Sandbox_merchant_2\",\"account_id\":\"\",\"account_name\":\"\",\"source_location\":\"63.241.252.2\",\"destination_location\":\"74.125.196.153\",\"metrics\":{\"X-GP-Version\":\"2020-12-22\"},\"action\":{\"id\":\"ACT_qOTwHG38UvuWwjcI6DBNu0uqbg8eoR\",\"type\":\"ACTION_SINGLE\",\"time_created\":\"2021-04-23T18:23:05.824Z\",\"result_code\":\"SUCCESS\",\"app_id\":\"P3LRVjtGRGxWQQJDE345mSkEh2KfdAyg\",\"app_name\":\"colleens_app\"}}";

            JsonDoc doc = JsonDoc.Parse(rawJson);

            // Act
            ActionSummary action = GpApiMapping.MapActionSummary(doc);

            // Assert
            Assert.AreEqual(doc.GetValue <string>("id"), action.Id);
            Assert.AreEqual(doc.GetValue <string>("type"), action.Type);
            Assert.AreEqual(doc.GetValue <DateTime>("time_created"), action.TimeCreated);
            Assert.AreEqual(doc.GetValue <string>("resource"), action.Resource);
            Assert.AreEqual(doc.GetValue <string>("version"), action.Version);
            Assert.AreEqual(doc.GetValue <string>("resource_id"), action.ResourceId);
            Assert.AreEqual(doc.GetValue <string>("resource_status"), action.ResourceStatus);
            Assert.AreEqual(doc.GetValue <string>("http_response_code"), action.HttpResponseCode);
            Assert.AreEqual(doc.GetValue <string>("response_code"), action.ResponseCode);
            Assert.AreEqual(doc.GetValue <string>("app_id"), action.AppId);
            Assert.AreEqual(doc.GetValue <string>("app_name"), action.AppName);
            Assert.AreEqual(doc.GetValue <string>("account_id"), action.AccountId);
            Assert.AreEqual(doc.GetValue <string>("account_name"), action.AccountName);
            Assert.AreEqual(doc.GetValue <string>("merchant_name"), action.MerchantName);
        }
        public static bool AreEqual(string expectedString, string compareString)
        {
            var expected = JsonDoc.Parse(expectedString);
            var compare  = JsonDoc.Parse(compareString);

            return(AreEqual(expected, compare));
        }
Exemplo n.º 7
0
        public static Transaction MapResponse(string rawResponse)
        {
            Transaction transaction = new Transaction();

            if (!string.IsNullOrEmpty(rawResponse))
            {
                JsonDoc json = JsonDoc.Parse(rawResponse);

                transaction.ResponseCode = json.Get("action")?.GetValue <string>("result_code");

                string actionType = json.Get("action")?.GetValue <string>("type");

                switch (actionType)
                {
                case BATCH_CLOSE:
                    transaction.BatchSummary = new BatchSummary {
                        BatchReference   = json.GetValue <string>("id"),
                        Status           = json.GetValue <string>("status"),
                        TotalAmount      = json.GetValue <string>("amount").ToAmount(),
                        TransactionCount = json.GetValue <int>("transaction_count"),
                    };
                    return(transaction);

                case PAYMENT_METHOD_CREATE:
                case PAYMENT_METHOD_DETOKENIZE:
                case PAYMENT_METHOD_EDIT:
                case PAYMENT_METHOD_DELETE:
                    transaction.Token           = json.GetValue <string>("id");
                    transaction.Timestamp       = json.GetValue <string>("time_created");
                    transaction.ReferenceNumber = json.GetValue <string>("reference");
                    transaction.CardType        = json.Get("card")?.GetValue <string>("brand");
                    transaction.CardNumber      = json.Get("card")?.GetValue <string>("number");
                    transaction.CardLast4       = json.Get("card")?.GetValue <string>("masked_number_last4");
                    transaction.CardExpMonth    = json.Get("card")?.GetValue <int>("expiry_month");
                    transaction.CardExpYear     = json.Get("card")?.GetValue <int>("expiry_year");
                    return(transaction);

                default:
                    break;
                }

                transaction.TransactionId       = json.GetValue <string>("id");
                transaction.BalanceAmount       = json.GetValue <string>("amount").ToAmount();
                transaction.Timestamp           = json.GetValue <string>("time_created");
                transaction.ResponseMessage     = json.GetValue <string>("status");
                transaction.ReferenceNumber     = json.GetValue <string>("reference");
                transaction.ClientTransactionId = json.GetValue <string>("reference");
                transaction.BatchSummary        = new BatchSummary {
                    BatchReference = json.GetValue <string>("batch_id")
                };
                transaction.Token              = json.Get("payment_method")?.GetValue <string>("id");
                transaction.AuthorizationCode  = json.Get("payment_method")?.GetValue <string>("result");
                transaction.CardType           = json.Get("payment_method")?.Get("card")?.GetValue <string>("brand");
                transaction.CardLast4          = json.Get("payment_method")?.Get("card")?.GetValue <string>("masked_number_last4");
                transaction.CvnResponseMessage = json.Get("payment_method")?.Get("card")?.GetValue <string>("cvv_result");
            }

            return(transaction);
        }
Exemplo n.º 8
0
        public override IDeviceResponse LineItem(string leftText, string rightText = null, string runningLeftText = null, string runningRightText = null)
        {
            var    requestId  = _controller.GetRequestId();
            var    response   = _controller.Send(TerminalUtilities.BuildUpaAdminRequest(requestId, EcrId, UpaTransType.LineItemDisplay, leftText, rightText));
            string jsonObject = Encoding.UTF8.GetString(response);
            var    jsonParse  = JsonDoc.Parse(jsonObject);

            return(new TransactionResponse(jsonParse));
        }
Exemplo n.º 9
0
        public override IDeviceResponse Reboot()
        {
            var    requestId  = _controller.GetRequestId();
            var    response   = _controller.Send(TerminalUtilities.BuildUpaAdminRequest(requestId, EcrId, UpaTransType.Reboot));
            string jsonObject = Encoding.UTF8.GetString(response);
            var    jsonParse  = JsonDoc.Parse(jsonObject);

            return(new TransactionResponse(jsonParse));
        }
Exemplo n.º 10
0
        public override IEODResponse EndOfDay()
        {
            var    requestId  = _controller.GetRequestId();
            var    response   = _controller.Send(TerminalUtilities.BuildUpaAdminRequest(requestId, EcrId, UpaTransType.EodProcessing));
            string jsonObject = Encoding.UTF8.GetString(response);
            var    jsonParse  = JsonDoc.Parse(jsonObject);

            return(new UpaEODResponse(jsonParse));
        }
Exemplo n.º 11
0
        public override ISAFResponse SendStoreAndForward()
        {
            var     requestId  = _controller.GetRequestId();
            var     response   = _controller.Send(TerminalUtilities.BuildUpaAdminRequest(requestId, EcrId, UpaTransType.SendSAF));
            string  jsonObject = Encoding.UTF8.GetString(response);
            JsonDoc doc        = JsonDoc.Parse(jsonObject);

            return(new UpaSAFResponse(doc));
        }
Exemplo n.º 12
0
 protected virtual string HandleResponse(GatewayResponse response)
 {
     if (response.StatusCode != HttpStatusCode.OK && response.StatusCode != HttpStatusCode.NoContent)
     {
         var parsed = JsonDoc.Parse(response.RawResponse);
         var error  = parsed.Get("error") ?? parsed;
         throw new GatewayException(string.Format("Status Code: {0} - {1}", response.StatusCode, error.GetValue <string>("message")));
     }
     return(response.RawResponse);
 }
Exemplo n.º 13
0
        public GpApi3DSecure2Tests()
        {
            // Create card data
            card = new CreditCardData {
                Number         = GpApi3DSTestCards.CARD_CHALLENGE_REQUIRED_V2_1,
                ExpMonth       = expMonth,
                ExpYear        = expYear,
                CardHolderName = "John Smith"
            };

            // Shipping address
            shippingAddress = new Address {
                StreetAddress1 = "Apartment 852",
                StreetAddress2 = "Complex 741",
                StreetAddress3 = "no",
                City           = "Chicago",
                PostalCode     = "5001",
                State          = "IL",
                CountryCode    = "840"
            };

            // Browser data
            browserData = new BrowserData {
                AcceptHeader        = "text/html,application/xhtml+xml,application/xml;q=9,image/webp,img/apng,*/*;q=0.8",
                ColorDepth          = ColorDepth.TWENTY_FOUR_BITS,
                IpAddress           = "123.123.123.123",
                JavaEnabled         = true,
                Language            = "en",
                ScreenHeight        = 1080,
                ScreenWidth         = 1920,
                ChallengeWindowSize = ChallengeWindowSize.WINDOWED_600X400,
                Timezone            = "0",
                UserAgent           =
                    "Mozilla/5.0 (Windows NT 6.1; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36"
            };

            // Mobile data
            mobileData =
                new MobileData {
                EncodedData            = "ew0KCSJEViI6ICIxLjAiLA0KCSJERCI6IHsNCgkJIkMwMDEiOiAiQW5kcm9pZCIsDQoJCSJDMDAyIjogIkhUQyBPbmVfTTgiLA0KCQkiQzAwNCI6ICI1LjAuMSIsDQoJCSJDMDA1IjogImVuX1VTIiwNCgkJIkMwMDYiOiAiRWFzdGVybiBTdGFuZGFyZCBUaW1lIiwNCgkJIkMwMDciOiAiMDY3OTc5MDMtZmI2MS00MWVkLTk0YzItNGQyYjc0ZTI3ZDE4IiwNCgkJIkMwMDkiOiAiSm9obidzIEFuZHJvaWQgRGV2aWNlIg0KCX0sDQoJIkRQTkEiOiB7DQoJCSJDMDEwIjogIlJFMDEiLA0KCQkiQzAxMSI6ICJSRTAzIg0KCX0sDQoJIlNXIjogWyJTVzAxIiwgIlNXMDQiXQ0KfQ0K"
                , ApplicationReference = "f283b3ec-27da-42a1-acea-f3f70e75bbdc"
                , SdkInterface         = SdkInterface.BOTH
                , EphemeralPublicKey   =
                    JsonDoc.Parse("{" +
                                  "\"kty\":\"EC\"," +
                                  "\"crv\":\"P-256\"," +
                                  "\"x\":\"WWcpTjbOqiu_1aODllw5rYTq5oLXE_T0huCPjMIRbkI\",\"y\":\"Wz_7anIeadV8SJZUfr4drwjzuWoUbOsHp5GdRZBAAiw\"" +
                                  "}"
                                  )
                , MaximumTimeout    = 50
                , ReferenceNumber   = "3DS_LOA_SDK_PPFU_020100_00007"
                , SdkTransReference = "b2385523-a66c-4907-ac3c-91848e8c0067"
            };
            mobileData.SetSdkUiTypes(SdkUiType.OOB);
        }
Exemplo n.º 14
0
        public void MapTransactionSummaryTest_FromObject()
        {
            // Arrange
            dynamic obj = new ExpandoObject();

            obj.id                                            = "TRN_TvY1QFXxQKtaFSjNaLnDVdo3PZ7ivz";
            obj.time_created                                  = DateTime.UtcNow;
            obj.status                                        = "PREAUTHORIZED";
            obj.type                                          = "SALE";
            obj.channel                                       = "CNP";
            obj.amount                                        = "10000";
            obj.currency                                      = "USD";
            obj.reference                                     = "My-TRANS-184398775";
            obj.batch_id                                      = "BATCH_123456";
            obj.country                                       = "US";
            obj.parent_resource_id                            = "PARENT_456123";
            obj.payment_method                                = new ExpandoObject();
            obj.payment_method.message                        = "SUCCESS";
            obj.payment_method.entry_mode                     = "ECOM";
            obj.payment_method.name                           = "James Mason";
            obj.payment_method.card                           = new ExpandoObject();
            obj.payment_method.card.brand                     = "VISA";
            obj.payment_method.card.authcode                  = "12345";
            obj.payment_method.card.brand_reference           = "TQ76bJf7qzkC30U0";
            obj.payment_method.card.arn                       = "ARN_123456798";
            obj.payment_method.card.masked_number_first6last4 = "411111XXXXXX1111";

            string rawJson = JsonConvert.SerializeObject(obj);

            // Act
            TransactionSummary transaction = GpApiMapping.MapTransactionSummary(JsonDoc.Parse(rawJson));

            // Assert
            Assert.AreEqual(obj.id, transaction.TransactionId);
            Assert.AreEqual(obj.time_created, transaction.TransactionDate);
            Assert.AreEqual(obj.status, transaction.TransactionStatus);
            Assert.AreEqual(obj.type, transaction.TransactionType);
            Assert.AreEqual(obj.channel, transaction.Channel);
            Assert.AreEqual((obj.amount as string).ToAmount(), transaction.Amount);
            Assert.AreEqual(obj.currency, transaction.Currency);
            Assert.AreEqual(obj.reference, transaction.ReferenceNumber);
            Assert.AreEqual(obj.reference, transaction.ClientTransactionId);
            Assert.AreEqual(obj.batch_id, transaction.BatchSequenceNumber);
            Assert.AreEqual(obj.country, transaction.Country);
            Assert.AreEqual(obj.parent_resource_id, transaction.OriginalTransactionId);
            Assert.AreEqual(obj.payment_method.message, transaction.GatewayResponseMessage);
            Assert.AreEqual(obj.payment_method.entry_mode, transaction.EntryMode);
            Assert.AreEqual(obj.payment_method.name, transaction.CardHolderName);
            Assert.AreEqual(obj.payment_method.card.brand, transaction.CardType);
            Assert.AreEqual(obj.payment_method.card.authcode, transaction.AuthCode);
            Assert.AreEqual(obj.payment_method.card.brand_reference, transaction.BrandReference);
            Assert.AreEqual(obj.payment_method.card.arn, transaction.AquirerReferenceNumber);
            Assert.AreEqual(obj.payment_method.card.masked_number_first6last4, transaction.MaskedCardNumber);
        }
Exemplo n.º 15
0
        private T MapResponse <T>(string rawResponse) where T : class
        {
            // this is for DELETE which returns nothing
            if (string.IsNullOrEmpty(rawResponse))
            {
                return(null);
            }

            // else do the whole shebang
            var response = JsonDoc.Parse(rawResponse);

            var type = Activator.CreateInstance <T>();

            if (type is Customer)
            {
                return(HydrateCustomer(response) as T);
            }
            else if (type is IEnumerable <Customer> )
            {
                var customers = new List <Customer>();
                foreach (var customer in response.GetEnumerator("results"))
                {
                    customers.Add(HydrateCustomer(customer));
                }
                return(customers as T);
            }
            else if (type is RecurringPaymentMethod)
            {
                return(HydratePaymentMethod(response) as T);
            }
            else if (type is IEnumerable <RecurringPaymentMethod> )
            {
                var methods = new List <RecurringPaymentMethod>();
                foreach (var method in response.GetEnumerator("results"))
                {
                    methods.Add(HydratePaymentMethod(method));
                }
                return(methods as T);
            }
            if (type is Schedule)
            {
                return(HydrateSchedule(response) as T);
            }
            else if (type is IEnumerable <Schedule> )
            {
                var schedules = new List <Schedule>();
                foreach (var schedule in response.GetEnumerator("results"))
                {
                    schedules.Add(HydrateSchedule(schedule));
                }
                return(schedules as T);
            }
            return(type);
        }
Exemplo n.º 16
0
        internal BasePayrollResponse(string rawResponse)
        {
            var doc = JsonDoc.Parse(rawResponse);

            MapResponseValues(doc);

            if (StatusCode != 200)
            {
                throw new ApiException(ResponseMessage);
            }
        }
Exemplo n.º 17
0
        internal List <string> ProcessValidationResult(string json)
        {
            var response         = JsonDoc.Parse(json);
            var validationErrors = new List <string>();

            MerchantInfo?.ProcessValidation(response, validationErrors);
            LegalInfo?.ProcessValidation(response, validationErrors);
            BusinessInfo?.ProcessValidation(response, validationErrors);

            // OPTIONALS
            Headquarters?.ProcessValidation(response, validationErrors);
            SalesMethods?.ProcessValidation(response, validationErrors);
            ProcessingMethod?.ProcessValidation(response, validationErrors);
            FutureDeliveryInfo?.ProcessValidation(response, validationErrors);
            GolfIndustry?.ProcessValidation(response, validationErrors);
            SalonIndustry?.ProcessValidation(response, validationErrors);
            LodgingResortInfo?.ProcessValidation(response, validationErrors);
            TransactionInfo?.ProcessValidation(response, validationErrors);
            EquipmentInfo?.ProcessValidation(response, validationErrors);
            ShippingOptions?.ProcessValidation(response, validationErrors);
            DepositOptions?.ProcessValidation(response, validationErrors);
            StatementOptions?.ProcessValidation(response, validationErrors);
            DisputeOptions?.ProcessValidation(response, validationErrors);

            // owners/officers
            for (int i = 0; i < 10; i++)
            {
                if (i < OwnerOfficers.Count)
                {
                    var owner = OwnerOfficers[i];
                    owner.Prefix = string.Format("OwnerOfficer{0}_", i + 1);
                    owner.ProcessValidation(response, validationErrors);
                }
                else
                {
                    continue;
                }
            }

            // banking info
            BankingInfo?.ProcessValidation(response, validationErrors);
            if (BankingInfo != null)
            {
                foreach (var account in BankingInfo.BankAccounts)
                {
                    account.Prefix = string.Format("MerchantAccount{0}_", BankingInfo.BankAccounts.IndexOf(account) + 1);
                    account.ProcessValidation(response, validationErrors);
                }
            }

            return(validationErrors);
        }
Exemplo n.º 18
0
        internal BaseGpApiResponse(string rawResponse, string resultsField)
        {
            ResultsField = resultsField;

            var doc = JsonDoc.Parse(rawResponse);

            MapResponseValues(doc);

            //if (StatusCode != 200)
            //{
            //    throw new ApiException(ResponseMessage);
            //}
        }
Exemplo n.º 19
0
        public Transaction ParseResponse(string json, bool encoded = false)
        {
            var response = JsonDoc.Parse(json, encoded ? JsonEncoders.Base64Encoder : null);

            var timestamp     = response.GetValue <string>("TIMESTAMP");
            var merchantId    = response.GetValue <string>("MERCHANT_ID");
            var orderId       = response.GetValue <string>("ORDER_ID");
            var result        = response.GetValue <string>("RESULT");
            var message       = response.GetValue <string>("MESSAGE");
            var transactionId = response.GetValue <string>("PASREF");
            var authCode      = response.GetValue <string>("AUTHCODE");

            var sha1Hash = response.GetValue <string>("SHA1HASH");
            var hash     = GenerationUtils.GenerateHash(_config.SharedSecret, timestamp, merchantId, orderId, result, message, transactionId, authCode);

            if (!hash.Equals(sha1Hash))
            {
                throw new ApiException("Incorrect hash. Please check your code and the Developers Documentation.");
            }

            // remainder of the values
            var rvalues = new Dictionary <string, string>();

            foreach (var key in response.Keys)
            {
                var value = response.GetValue <string>(key);
                if (value != null)
                {
                    rvalues.Add(key, value);
                }
            }

            return(new Transaction {
                AuthorizedAmount = response.GetValue <decimal>("AMOUNT"),
                AutoSettleFlag = response.GetValue <string>("AUTO_SETTLE_FLAG"),
                CvnResponseCode = response.GetValue <string>("CVNRESULT"),
                ResponseCode = result,
                ResponseMessage = message,
                AvsResponseCode = response.GetValue <string>("AVSPOSTCODERESULT"),
                Timestamp = timestamp,
                TransactionReference = new TransactionReference {
                    AuthCode = authCode,
                    OrderId = orderId,
                    PaymentMethodType = PaymentMethodType.Credit,
                    TransactionId = transactionId
                },
                ResponseValues = rvalues
            });
        }
Exemplo n.º 20
0
        internal TransactionResponse DoTransaction(IDeviceMessage request)
        {
            request.AwaitResponse = true;
            var response = _connector.Send(request);

            if (response == null)
            {
                return(null);
            }

            string jsonObject = Encoding.UTF8.GetString(response);
            var    jsonParse  = JsonDoc.Parse(jsonObject);

            return(new TransactionResponse(jsonParse));
        }
Exemplo n.º 21
0
        public void MapResponseTest_BatchClose()
        {
            // Arrange
            string rawJson = "{\"id\":\"BAT_631762-460\",\"time_last_updated\":\"2021-04-23T18:54:52.467Z\",\"status\":\"CLOSED\",\"amount\":\"869\",\"currency\":\"USD\",\"country\":\"US\",\"transaction_count\":2,\"action\":{\"id\":\"ACT_QUuw7OPd9Rw8n72oaVOmVlQXpuhLUZ\",\"type\":\"CLOSE\",\"time_created\":\"2021-04-23T18:54:52.467Z\",\"result_code\":\"SUCCESS\",\"app_id\":\"P3LRVjtGRGxWQQJDE345mSkEh2KfdAyg\",\"app_name\":\"colleens_app\"}}";

            // Act
            Transaction transaction = GpApiMapping.MapResponse(rawJson);

            // Assert
            Assert.IsNotNull(transaction?.BatchSummary);
            JsonDoc doc = JsonDoc.Parse(rawJson);

            Assert.AreEqual(doc.GetValue <string>("id"), transaction?.BatchSummary?.BatchReference);
            Assert.AreEqual(doc.GetValue <string>("status"), transaction?.BatchSummary?.Status);
            Assert.AreEqual(doc.GetValue <string>("amount").ToAmount(), transaction?.BatchSummary?.TotalAmount);
            Assert.AreEqual(doc.GetValue <int>("transaction_count"), transaction?.BatchSummary?.TransactionCount);
        }
Exemplo n.º 22
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);
        }
Exemplo n.º 23
0
        private bool IsNonReadyResponse(byte[] responseMessage)
        {
            var responseMessageString = System.Text.Encoding.UTF8.GetString(responseMessage);
            var response = JsonDoc.Parse(responseMessageString);
            var data     = response.Get("data");

            if (data == null)
            {
                return(false);
            }
            var cmdResult = data.Get("cmdResult");

            return(
                data.GetValue <string>("response") == UpaTransType.Reboot ||
                (cmdResult != null && cmdResult.GetValue <string>("result") == "Failed")
                );
        }
Exemplo n.º 24
0
        protected override string HandleResponse(GatewayResponse response)
        {
            if (response.StatusCode != HttpStatusCode.OK && response.StatusCode != HttpStatusCode.NoContent)
            {
                var parsed = JsonDoc.Parse(response.RawResponse);
                if (parsed.Has("error_code"))
                {
                    string errorCode                = parsed.GetValue <string>("error_code");
                    string detailedErrorCode        = parsed.GetValue <string>("detailed_error_code");
                    string detailedErrorDescription = parsed.GetValue <string>("detailed_error_description");

                    throw new GatewayException($"Status Code: {response.StatusCode} - {detailedErrorDescription}", errorCode, detailedErrorCode);
                }
                throw new GatewayException($"Status Code: {response.StatusCode}", responseMessage: response.RawResponse);
            }
            return(response.RawResponse);
        }
Exemplo n.º 25
0
        public static Transaction MapResponse(string rawResponse)
        {
            Transaction transaction = new Transaction();

            if (!string.IsNullOrEmpty(rawResponse))
            {
                JsonDoc json = JsonDoc.Parse(rawResponse);

                // ToDo: Map transaction values
                transaction.TransactionId   = json.GetValue <string>("id");
                transaction.BalanceAmount   = json.GetValue <string>("amount").ToAmount();
                transaction.Timestamp       = json.GetValue <string>("time_created");
                transaction.ResponseMessage = json.GetValue <string>("status");
                transaction.ReferenceNumber = json.GetValue <string>("reference");
                transaction.BatchSummary    = new BatchSummary {
                    SequenceNumber = json.GetValue <string>("batch_id")
                };
                transaction.ResponseCode = json.Get("action").GetValue <string>("result_code");
                transaction.Token        = json.GetValue <string>("id");

                if (json.Has("payment_method"))
                {
                    JsonDoc paymentMethod = json.Get("payment_method");
                    transaction.AuthorizationCode = paymentMethod.GetValue <string>("result");
                    if (paymentMethod.Has("card"))
                    {
                        JsonDoc card = paymentMethod.Get("card");
                        transaction.CardType           = card.GetValue <string>("brand");
                        transaction.CardLast4          = card.GetValue <string>("masked_number_last4");
                        transaction.CvnResponseMessage = card.GetValue <string>("cvv_result");
                    }
                }
                if (json.Has("card"))
                {
                    JsonDoc card = json.Get("card");
                    transaction.CardNumber   = card.GetValue <string>("number");
                    transaction.CardType     = card.GetValue <string>("brand");
                    transaction.CardExpMonth = card.GetValue <int>("expiry_month");
                    transaction.CardExpYear  = card.GetValue <int>("expiry_year");
                }
            }

            return(transaction);
        }
Exemplo n.º 26
0
        public void MapResponseTest_CreateStoredPaymentMethod()
        {
            // Arrange
            string rawJson = "{\"id\":\"PMT_e150ba7c-bbbd-41fe-bc04-f21d18def2a1\",\"time_created\":\"2021-04-26T14:59:00.813Z\",\"status\":\"ACTIVE\",\"usage_mode\":\"MULTIPLE\",\"merchant_id\":\"MER_c4c0df11039c48a9b63701adeaa296c3\",\"merchant_name\":\"Sandbox_merchant_2\",\"account_id\":\"TKA_eba30a1b5c4a468d90ceeef2ffff7f5e\",\"account_name\":\"Tokenization\",\"reference\":\"9486a9e8-d8bd-4fd2-877c-796d07f3a2ce\",\"card\":{\"masked_number_last4\":\"XXXXXXXXXXXX1111\",\"brand\":\"VISA\",\"expiry_month\":\"12\",\"expiry_year\":\"25\"},\"action\":{\"id\":\"ACT_jFOurWcX9CvA8UKtEywVpxArNEryvZ\",\"type\":\"PAYMENT_METHOD_CREATE\",\"time_created\":\"2021-04-26T14:59:00.813Z\",\"result_code\":\"SUCCESS\",\"app_id\":\"P3LRVjtGRGxWQQJDE345mSkEh2KfdAyg\",\"app_name\":\"colleens_app\"}}";

            // Act
            Transaction transaction = GpApiMapping.MapResponse(rawJson);

            // Assert
            JsonDoc doc = JsonDoc.Parse(rawJson);

            Assert.AreEqual(doc.GetValue <string>("id"), transaction.Token);
            Assert.AreEqual(doc.GetValue <string>("time_created"), transaction.Timestamp);
            Assert.AreEqual(doc.GetValue <string>("reference"), transaction.ReferenceNumber);
            Assert.AreEqual(doc.Get("card")?.GetValue <string>("brand"), transaction.CardType);
            Assert.AreEqual(doc.Get("card")?.GetValue <string>("number"), transaction.CardNumber);
            Assert.AreEqual(doc.Get("card")?.GetValue <string>("masked_number_last4"), transaction.CardLast4);
            Assert.AreEqual(doc.Get("card")?.GetValue <int>("expiry_month"), transaction.CardExpMonth);
            Assert.AreEqual(doc.Get("card")?.GetValue <int>("expiry_year"), transaction.CardExpYear);
        }
Exemplo n.º 27
0
        public static Transaction Map3DSecureData(string rawResponse)
        {
            if (!string.IsNullOrEmpty(rawResponse))
            {
                JsonDoc json = JsonDoc.Parse(rawResponse);

                return(new Transaction {
                    ThreeDSecure = new ThreeDSecure {
                        ServerTransactionId = json.GetValue <string>("id"),
                        Status = json.GetValue <string>("status"),
                        Currency = json.GetValue <string>("currency"),
                        Amount = json.GetValue <string>("amount").ToAmount(),

                        Version = Parse3DSVersion(json.Get("three_ds")?.GetValue <string>("message_version")),
                        MessageVersion = json.Get("three_ds")?.GetValue <string>("message_version"),
                        DirectoryServerStartVersion = json.Get("three_ds")?.GetValue <string>("ds_protocol_version_start"),
                        DirectoryServerEndVersion = json.Get("three_ds")?.GetValue <string>("ds_protocol_version_end"),
                        DirectoryServerTransactionId = json.Get("three_ds")?.GetValue <string>("ds_trans_ref"),
                        AcsStartVersion = json.Get("three_ds")?.GetValue <string>("acs_protocol_version_start"),
                        AcsEndVersion = json.Get("three_ds")?.GetValue <string>("acs_protocol_version_end"),
                        AcsTransactionId = json.Get("three_ds")?.GetValue <string>("acs_trans_ref"),
                        Enrolled = json.Get("three_ds")?.GetValue <string>("enrolled_status"),
                        Eci = json.Get("three_ds")?.GetValue <string>("eci")?.ToInt32(),
                        AuthenticationValue = json.Get("three_ds")?.GetValue <string>("authentication_value"),
                        ChallengeMandated = json.Get("three_ds")?.GetValue <string>("challenge_status") == "MANDATED",
                        IssuerAcsUrl = !string.IsNullOrEmpty(json.Get("three_ds")?.GetValue <string>("method_url")) ?
                                       json.Get("three_ds")?.GetValue <string>("method_url") :
                                       json.Get("three_ds")?.GetValue <string>("acs_challenge_request_url"),
                        ChallengeReturnUrl = json.Get("notifications")?.GetValue <string>("challenge_return_url"),
                        SessionDataFieldName = json.Get("three_ds")?.GetValue <string>("session_data_field_name"),
                        MessageType = json.Get("three_ds")?.GetValue <string>("message_type"),
                        PayerAuthenticationRequest = (!string.IsNullOrEmpty(json.Get("three_ds")?.Get("method_data")?.GetValue <string>("encoded_method_data"))) ?
                                                     json.Get("three_ds")?.Get("method_data")?.GetValue <string>("encoded_method_data") :
                                                     json.Get("three_ds")?.GetValue <string>("challenge_value"),
                        StatusReason = json.Get("three_ds")?.GetValue <string>("status_reason"),
                        MessageCategory = json.Get("three_ds")?.GetValue <string>("message_category"),
                    }
                });
            }
            return(new Transaction());
        }
Exemplo n.º 28
0
        public void MapMapStoredPaymentMethodSummaryTest()
        {
            // Arrange
            string rawJson = "{\"id\":\"PMT_3502a05c-0a79-469b-bff9-994b665ce9d9\",\"time_created\":\"2021-04-23T18:46:57.000Z\",\"status\":\"ACTIVE\",\"merchant_id\":\"MER_c4c0df11039c48a9b63701adeaa296c3\",\"merchant_name\":\"Sandbox_merchant_2\",\"account_id\":\"TKA_eba30a1b5c4a468d90ceeef2ffff7f5e\",\"account_name\":\"Tokenization\",\"reference\":\"faed4ae3-1dd6-414a-bd7e-3a585715d9cc\",\"card\":{\"number_last4\":\"xxxxxxxxxxxx1111\",\"brand\":\"VISA\",\"expiry_month\":\"12\",\"expiry_year\":\"25\"},\"action\":{\"id\":\"ACT_wFGcHivudqleji9jA7S4MTapAHCTkp\",\"type\":\"PAYMENT_METHOD_SINGLE\",\"time_created\":\"2021-04-23T18:47:01.057Z\",\"result_code\":\"SUCCESS\",\"app_id\":\"P3LRVjtGRGxWQQJDE345mSkEh2KfdAyg\",\"app_name\":\"colleens_app\"}}";

            JsonDoc doc = JsonDoc.Parse(rawJson);

            // Act
            StoredPaymentMethodSummary paymentMethod = GpApiMapping.MapStoredPaymentMethodSummary(doc);

            // Assert
            Assert.AreEqual(doc.GetValue <string>("id"), paymentMethod.Id);
            Assert.AreEqual(doc.GetValue <DateTime>("time_created"), paymentMethod.TimeCreated);
            Assert.AreEqual(doc.GetValue <string>("status"), paymentMethod.Status);
            Assert.AreEqual(doc.GetValue <string>("reference"), paymentMethod.Reference);
            Assert.AreEqual(doc.GetValue <string>("name"), paymentMethod.Name);
            Assert.AreEqual(doc.Get("card")?.GetValue <string>("number_last4"), paymentMethod.CardLast4);
            Assert.AreEqual(doc.Get("card")?.GetValue <string>("brand"), paymentMethod.CardType);
            Assert.AreEqual(doc.Get("card")?.GetValue <string>("expiry_month"), paymentMethod.CardExpMonth);
            Assert.AreEqual(doc.Get("card")?.GetValue <string>("expiry_year"), paymentMethod.CardExpYear);
        }
Exemplo n.º 29
0
        internal override ITerminalReport ProcessReport(TerminalReportBuilder builder)
        {
            var response = Send(BuildReportTransaction(builder));

            string jsonObject = Encoding.UTF8.GetString(response);
            var    jsonParse  = JsonDoc.Parse(jsonObject);

            switch (builder.ReportType)
            {
            case TerminalReportType.GetSAFReport:
                return(new SafReportResponse(jsonParse));

            case TerminalReportType.GetBatchReport:
                return(new BatchReportResponse(jsonParse));

            case TerminalReportType.GetOpenTabDetails:
                return(new OpenTabDetailsResponse(jsonParse));

            default: return(null);
            }
        }
Exemplo n.º 30
0
        public void VerifyResponseValues()
        {
            var service = new HostedService(new GpEcomConfig {
                MerchantId   = "MerchantId",
                AccountId    = "internet",
                SharedSecret = "secret",
            });

            var responseJson = "{ \"MERCHANT_ID\": \"MerchantId\", \"ACCOUNT\": \"internet\", \"ORDER_ID\": \"GTI5Yxb0SumL_TkDMCAxQA\", \"AMOUNT\": \"1999\", \"TIMESTAMP\": \"20170725154824\", \"SHA1HASH\": \"843680654f377bfa845387fdbace35acc9d95778\", \"RESULT\": \"00\",  \"MERCHANT_RESPONSE_URL\": \"https://www.example.com/response\", \"AUTHCODE\": \"12345\", \"CARD_PAYMENT_BUTTON\": \"Place Order\", \"AVSADDRESSRESULT\": \"M\", \"AVSPOSTCODERESULT\": \"M\", \"BATCHID\": \"445196\", \"MESSAGE\": \"[ test system ] Authorised\", \"PASREF\": \"15011597872195765\", \"CVNRESULT\": \"M\"}";
            var response     = service.ParseResponse(responseJson, false);

            var doc = JsonDoc.Parse(responseJson);

            Assert.IsNotNull(response.ResponseValues);
            Assert.AreEqual(doc.Keys.Count, response.ResponseValues.Count);
            foreach (var key in doc.Keys)
            {
                var strValue = doc.GetValue <string>(key);
                Assert.AreEqual(strValue, response.ResponseValues[key]);
            }
        }