Skip to content

Commit

Permalink
Added card detail, card removal
Browse files Browse the repository at this point in the history
  • Loading branch information
pmaryska committed Jul 17, 2024
1 parent 9e49d79 commit 21186ca
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 4 deletions.
20 changes: 20 additions & 0 deletions GoPay.net-sdk/src/GPConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Net;
using Newtonsoft.Json;
using RestSharp.Serializers.NewtonsoftJson;
using gopay_dotnet_standard_api.src.Model.Payment;

namespace GoPay
{
Expand Down Expand Up @@ -369,6 +370,25 @@ public SupercashPayment GetSupercashCoupon(long couponId)
return ProcessResponse<SupercashPayment>(response);
}

/// <exception cref="GPClientException"></exception>
public Card GetCardDetail(long cardId)
{
var restRequest = CreateRestRequest(@"/payments/cards/{card_id}", null, null, Method.Get);
restRequest.AddParameter("card_id", cardId, ParameterType.UrlSegment);
var response = Client.Execute(restRequest);

return ProcessResponse<Card>(response);
}

/// <exception cref="GPClientException"></exception>
public RestResponse DeleteCard(long cardId)
{
var restRequest = CreateRestRequest(@"/payments/cards/{card_id}", null, null, Method.Delete);
restRequest.AddParameter("card_id", cardId, ParameterType.UrlSegment);

return Client.Execute(restRequest);
}

private T ProcessResponse<T>(RestResponse response)
{
OnIncomingDataEvent(response);
Expand Down
63 changes: 63 additions & 0 deletions GoPay.net-sdk/src/Model/Payment/Card.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using GoPay.Model.Payments;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Linq;

namespace gopay_dotnet_standard_api.src.Model.Payment
{
public class Card
{
public enum CardStatus
{
ACTIVE,
DELETED
}

public Card()
{

}

[JsonProperty("card_id")]
public long CardId { get; set; }

[JsonProperty("card_number")]
public string CardNumber { get; set; }

[JsonProperty("card_expiration")]
public string CardExpiration { get; set; }

[JsonProperty("card_brand")]
public string CardBrand { get; set; }

[JsonProperty("card_issuer_country")]
public string CardIssuerCountry { get; set; }

[JsonProperty("card_issuer_bank")]
public string CardIssuerBank { get; set; }

[JsonProperty("card_fingerprint")]
public string CardFingerprint { get; set; }

[JsonProperty("card_token")]
public string CardToken { get; set; }

[JsonProperty("status")]
[JsonConverter(typeof(StringEnumConverter))]
public Nullable<CardStatus> Status;

[JsonProperty("real_masked_pan")]
public string RealMaskedPan { get; set; }

[JsonProperty("card_art_url")]
public string CardArtUrl { get; set; }

public override string ToString()
{
return base.ToString();
}
}
}
52 changes: 52 additions & 0 deletions GoPay.net-sdkTests/src/Tests/CardTokenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using GoPay.Common;
using GoPay.Model.Payments;
using GoPay.Model.Payment;
using gopay_dotnet_standard_api.src.Model.Payment;
using RestSharp;

namespace GoPay.Tests
{
Expand Down Expand Up @@ -126,5 +128,55 @@ public void GPConnectorTestCardTokenPaymentStatus()
}
}

// [TestMethod()]
public void GPConnectorTestCardDetail()
{
var connector = new GPConnector(TestUtils.API_URL, TestUtils.CLIENT_ID, TestUtils.CLIENT_SECRET);
long cardId = 3824914275;

try
{
Card result = connector.GetAppToken().GetCardDetail(cardId);
Assert.IsNotNull(result);
Assert.IsNotNull(result.CardId);
Assert.AreEqual(cardId, result.CardId);
Assert.AreEqual("Visa Gold", result.CardBrand);
Console.WriteLine(result.ToString());
}
catch (GPClientException ex)
{
Console.WriteLine("Card Detail ERROR");
var err = ex.Error;
DateTime date = err.DateIssued;
foreach (var element in err.ErrorMessages)
{

}
}
}

// [TestMethod()]
public void GPConnectorTestCardDelete()
{
var connector = new GPConnector(TestUtils.API_URL, TestUtils.CLIENT_ID, TestUtils.CLIENT_SECRET);
long cardId = 3824914275;

try
{
RestResponse response = connector.GetAppToken().DeleteCard(cardId);
Assert.IsNotNull(response.IsSuccessful);
}
catch (GPClientException ex)
{
Console.WriteLine("Card Detail ERROR");
var err = ex.Error;
DateTime date = err.DateIssued;
foreach (var element in err.ErrorMessages)
{

}
}
}

}
}
8 changes: 4 additions & 4 deletions Package.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
<package >
<metadata>
<id>GoPay.NET</id>
<version>1.2.6</version>
<authors>Stanislav Kouba, Frantisek Sichinger</authors>
<version>1.2.7</version>
<authors>Stanislav Kouba, Frantisek Sichinger, Patrik Maryska</authors>
<owners>GoPay s.r.o.</owners>
<license type="expression">MIT</license>
<projectUrl>https://github.com/gopaycommunity/gopay-dotnet-api</projectUrl>
<icon>images/icon.png</icon>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>GoPay .NET sdk</description>
<releaseNotes>Fixed languages</releaseNotes>
<copyright>Copyright 2023</copyright>
<releaseNotes>Added card detail, card removal</releaseNotes>
<copyright>Copyright 2024</copyright>
<tags>GoPay Platebni brana</tags>
<dependencies>
<group targetFramework=".NETStandard2.0">
Expand Down

0 comments on commit 21186ca

Please sign in to comment.