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); } }
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); }
public Transaction ManageTransaction(ManagementBuilder builder) { if (string.IsNullOrEmpty(AccessToken)) { SignIn(); } GpApiRequest request = GpApiManagementRequestBuilder.BuildRequest(builder, this); if (request != null) { var response = DoTransaction(request.Verb, request.Endpoint, request.RequestBody, request.QueryStringParams, builder.IdempotencyKey); return(GpApiMapping.MapResponse(response)); } return(null); }
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); }
public Transaction ProcessAuthorization(AuthorizationBuilder builder) { if (string.IsNullOrEmpty(AccessToken)) { SignIn(); } GpApiRequest request = GpApiAuthorizationRequestBuilder.BuildRequest(builder, this); if (request != null) { var response = DoTransaction(request.Verb, request.Endpoint, request.RequestBody, request.QueryStringParams, builder.IdempotencyKey); if (builder.PaymentMethod is AlternativePaymentMethod) { return(GpApiMapping.MapResponseAPM(response)); } return(GpApiMapping.MapResponse(response)); } return(null); }