Skip to content

Commit

Permalink
Merge pull request #39 from PinchPayments/multi-nonce-responses
Browse files Browse the repository at this point in the history
Added multi-nonce support to the responses
  • Loading branch information
dkarzon authored Nov 14, 2023
2 parents 1fb78e5 + d91c2d8 commit 4ae7a78
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 29 deletions.
21 changes: 17 additions & 4 deletions .github/workflows/Release_Package.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: Upload dotnet package

on:
release:
types: [created]
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'

jobs:
deploy:
Expand All @@ -19,12 +20,24 @@ jobs:
env:
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/v/}

- name: Build
run: dotnet build --configuration Release

- name: Create the package
run: dotnet pack --configuration Release
run: dotnet pack --configuration Release -p:PackageVersion=${{ steps.get_version.outputs.VERSION }}

- name: Publish the package to GPR
working-directory: ./src/Pinch.SDK
run: dotnet nuget push ./bin/Release/*.nupkg
run: dotnet nuget push ./bin/Release/*.nupkg

- name: Publish Github Release
uses: marvinpinto/[email protected]
with:
title: v${{ steps.get_version.outputs.VERSION }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
prerelease: false
files: ./bin/Release/*.nupkg
31 changes: 18 additions & 13 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
![Pinch .NET](https://user-images.githubusercontent.com/241857/124199780-118b3a80-db17-11eb-8fa4-5c0cb97f9de4.png)

# Pinch SDK for .NET
The Pinch SDK for .NET helps developers build web, desktop, Silverlight, Windows Phone and Windows Store applications that integrate with Pinch.
The Pinch SDK for .NET helps developers build applications that integrate with Pinch across all supported .NET platforms.

## NuGet

Install-Package Pinch.SDK
## Installation
Using the .NET Core command-line interface (CLI) tools:

dotnet add package Pinch.SDK

*The Pinch SDK for .NET binaries are only distributed via nuget. For those using older versions of Visual Studio that
does not support NuGet Package Manager, please download the [command line version of NuGet.exe](http://nuget.codeplex.com/releases/view/58939) and run the following
command.*
Using the NuGet Command Line Interface (CLI):

nuget install Pinch.SDK

If you would like to get an older version of the the binaries please use the following command.

nuget install Pinch.SDK -v 0.17.1
Using the Package Manager Console:

Install-Package Pinch.SDK

From within Visual Studio:

1. Open the Solution Explorer.
2. Right-click on a project within your solution.
3. Click on Manage NuGet Packages...
4. Click on the Browse tab and search for "Pinch.SDK".
5. Click on the Pinch.SDK package, select the appropriate version in the right-tab and click Install.

See the [Pinch.SDK nuget page](https://www.nuget.org/packages/Pinch.SDK) for all previous versions.


## Documentation
You can find the documentation for this project [here](https://docs.getpinch.com.au/).
Check out the [Pinch API documentation here](https://docs.getpinch.com.au/) for the full API reference as well as example usages and guides on using the Pinch API.

## Features
* Compatible with all Pinch REST API methods.
* Supports both sandboxed test environment and production.
* Sample applications and documentation are provided to get you started quickly.

## Supported Platforms
* .NET 3.5 (Client Profile and Full Profile)
* .NET 4.0 (Client Profile and Full Profile)
* .NET 4.5
* .NET Standard 2
6 changes: 5 additions & 1 deletion src/Pinch.SDK/ApiResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Pinch.SDK.Converters;
using Pinch.SDK.Helpers;

namespace Pinch.SDK
{
public class NonceApiResponse<T> : ApiResponse<T>
{
public bool IsNonceReplay { get; set; }
public string Nonce { get; set; }

[JsonConverter(typeof(SingleOrArrayConverter<string>))]
public List<string> Nonce { get; set; }
}

public class ApiResponse
Expand Down
43 changes: 43 additions & 0 deletions src/Pinch.SDK/Converters/SingleOrArrayConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Pinch.SDK.Converters
{
internal class SingleOrArrayConverter<T> : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return (objectType == typeof(List<T>));
}

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
JToken token = JToken.Load(reader);
if (token.Type == JTokenType.Array)
{
return token.ToObject<List<T>>();
}
return new List<T> { token.ToObject<T>() };
}

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
List<T> list = (List<T>)value;
if (list.Count == 1)
{
value = list[0];
}
serializer.Serialize(writer, value);
}

public override bool CanWrite
{
get { return true; }
}
}
}
5 changes: 4 additions & 1 deletion src/Pinch.SDK/Helpers/HttpClientHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Pinch.SDK.Converters;

namespace Pinch.SDK.Helpers
{
Expand Down Expand Up @@ -98,7 +99,9 @@ public class QuickResponse
public List<ApiError> Errors { get; set; }

public bool IsNonceReplay { get; set; }
public string Nonce { get; set; }

[JsonConverter(typeof(SingleOrArrayConverter<string>))]
public List<string> Nonce { get; set; }

public QuickResponse()
{
Expand Down
10 changes: 8 additions & 2 deletions src/Pinch.SDK/Helpers/NonceResponseDto.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
namespace Pinch.SDK.Helpers
using Newtonsoft.Json;
using Pinch.SDK.Converters;
using System.Collections.Generic;

namespace Pinch.SDK.Helpers
{
public class NonceResponseDto
{
public bool IsNonceReplay { get; set; }
public string Nonce { get; set; }

[JsonConverter(typeof(SingleOrArrayConverter<string>))]
public List<string> Nonce { get; set; }
}

public class NonceResponseDto<T> : NonceResponseDto
Expand Down
5 changes: 4 additions & 1 deletion src/Pinch.SDK/Payments/PaymentDetailed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Pinch.SDK.Converters;
using Pinch.SDK.Payers;
using Pinch.SDK.Subscriptions;

Expand Down Expand Up @@ -77,7 +79,8 @@ public class PaymentDetailed
/// <summary>
/// The Nonce that was sent with the initial request
/// </summary>
public string Nonce { get; set; }
[JsonConverter(typeof(SingleOrArrayConverter<string>))]
public List<string> Nonce { get; set; }

public PaymentDetailed()
{
Expand Down
9 changes: 2 additions & 7 deletions src/Pinch.SDK/Pinch.SDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,22 @@
<Description>The easiest way to integrate your .net application with Pinch Payments. Create payers, add payments, receive webhooks, fetch payments, get paid. Really all the good stuff. It's for Australian businesses if you didn't already know. I'll assume you did if you got this far, if not, Welcome! but you should probably check out getpinch.com.au to get up to speed.</Description>
<AssemblyTitle>Pinch Payments</AssemblyTitle>
<Authors>Pinch Payments</Authors>
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Pinch.SDK</AssemblyName>
<PackageId>Pinch.SDK</PackageId>
<PackageTags>payments;pinch;sdk;direct debit</PackageTags>
<PackageIconUrl>https://raw.githubusercontent.com/PinchPayments/Pinch.SDK/master/assets/img/circle_logo_64x64.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/PinchPayments/Pinch.SDK</PackageProjectUrl>
<RepositoryUrl>https://github.com/PinchPayments/Pinch.SDK</RepositoryUrl>
<Version>0.21.0</Version>
<Version>$(PackageVersion)</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="IdentityModel" Version="2.0.2" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

<ItemGroup>
<Reference Include="System.ComponentModel.DataAnnotations" />
</ItemGroup>
Expand Down

0 comments on commit 4ae7a78

Please sign in to comment.