예제 #1
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);
        }
예제 #2
0
        public void MapTransactionSummaryTest_NullDates()
        {
            // Arrange
            string rawJson = "{\"id\":\"TRN_TvY1QFXxQKtaFSjNaLnDVdo3PZ7ivz\",\"time_created\":\"\",\"time_last_updated\":\"\",\"status\":\"PREAUTHORIZED\",\"type\":\"SALE\",\"merchant_id\":\"MER_c4c0df11039c48a9b63701adeaa296c3\",\"merchant_name\":\"Sandbox_merchant_2\",\"account_id\":\"TRA_6716058969854a48b33347043ff8225f\",\"account_name\":\"Transaction_Processing\",\"channel\":\"CNP\",\"amount\":\"10000\",\"currency\":\"CAD\",\"reference\":\"My-TRANS-184398775\",\"description\":\"41e7877b-da90-4c5f-befe-7f024b96311e\",\"order_reference\":\"\",\"time_created_reference\":\"\",\"batch_id\":\"\",\"initiator\":\"\",\"country\":\"\",\"language\":\"\",\"ip_address\":\"97.107.232.5\",\"site_reference\":\"\",\"payment_method\":{\"result\":\"00\",\"message\":\"SUCCESS\",\"entry_mode\":\"ECOM\",\"name\":\"NAME NOT PROVIDED\",\"card\":{\"funding\":\"CREDIT\",\"brand\":\"VISA\",\"authcode\":\"12345\",\"brand_reference\":\"TQ76bJf7qzkC30U0\",\"masked_number_first6last4\":\"411111XXXXXX1111\",\"cvv_indicator\":\"PRESENT\",\"cvv_result\":\"MATCHED\",\"avs_address_result\":\"MATCHED\",\"avs_postal_code_result\":\"MATCHED\"}},\"action_create_id\":\"ACT_TvY1QFXxQKtaFSjNaLnDVdo3PZ7ivz\",\"parent_resource_id\":\"TRN_TvY1QFXxQKtaFSjNaLnDVdo3PZ7ivz\",\"action\":{\"id\":\"ACT_kLkU0qND7wyuW0Br76ZNyAnlPTjHsb\",\"type\":\"TRANSACTION_SINGLE\",\"time_created\":\"\",\"result_code\":\"SUCCESS\",\"app_id\":\"JF2GQpeCrOivkBGsTRiqkpkdKp67Gxi0\",\"app_name\":\"test_app\"}}";

            JsonDoc doc = JsonDoc.Parse(rawJson);

            // Act
            TransactionSummary transaction = GpApiMapping.MapTransactionSummary(doc);

            // Assert
            Assert.AreEqual(doc.GetValue <string>("id"), transaction.TransactionId);
            Assert.IsNull(transaction.TransactionDate);
            Assert.AreEqual(doc.GetValue <string>("status"), transaction.TransactionStatus);
            Assert.AreEqual(doc.GetValue <string>("type"), transaction.TransactionType);
            Assert.AreEqual(doc.GetValue <string>("channel"), transaction.Channel);
            Assert.AreEqual(doc.GetValue <string>("amount").ToAmount(), transaction.Amount);
            Assert.AreEqual(doc.GetValue <string>("currency"), transaction.Currency);
            Assert.AreEqual(doc.GetValue <string>("reference"), transaction.ReferenceNumber);
            Assert.AreEqual(doc.GetValue <string>("reference"), transaction.ClientTransactionId);
            Assert.AreEqual(doc.GetValue <string>("batch_id"), transaction.BatchSequenceNumber);
            Assert.AreEqual(doc.GetValue <string>("country"), transaction.Country);
            Assert.AreEqual(doc.GetValue <string>("parent_resource_id"), transaction.OriginalTransactionId);

            var paymentMethod = doc.Get("payment_method");

            Assert.AreEqual(paymentMethod?.GetValue <string>("message"), transaction.GatewayResponseMessage);
            Assert.AreEqual(paymentMethod?.GetValue <string>("entry_mode"), transaction.EntryMode);
            Assert.AreEqual(paymentMethod?.GetValue <string>("name"), transaction.CardHolderName);

            var card = paymentMethod.Get("card");

            Assert.AreEqual(card?.GetValue <string>("brand"), transaction.CardType);
            Assert.AreEqual(card?.GetValue <string>("authcode"), transaction.AuthCode);
            Assert.AreEqual(card?.GetValue <string>("brand_reference"), transaction.BrandReference);
            Assert.AreEqual(card?.GetValue <string>("arn"), transaction.AquirerReferenceNumber);
            Assert.AreEqual(card?.GetValue <string>("masked_number_first6last4"), transaction.MaskedCardNumber);
        }