Skip to content

Commit

Permalink
Merchant Statements (#36)
Browse files Browse the repository at this point in the history
* Removed VerificationSession

* SDK to version 0.20.0

* added Statement API endpoints

* Update BaseClient.cs

* Update StatementsClient.cs

* Changed responses on statement file streams

* Added Github Action workflows

* updated property description
  • Loading branch information
anthonyvscode authored Oct 19, 2023
1 parent 11350c6 commit 87835d7
Show file tree
Hide file tree
Showing 14 changed files with 272 additions and 58 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/PR_Build_Check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: PR_Build_Check

on:
pull_request:
branches: [ "master" ]

jobs:
build:
runs-on: ubuntu-latest
env:
CI: "" # Prevent node build warnings emitting as run errors.

steps:
- uses: actions/checkout@v3

- name: Setup dotnet
uses: actions/[email protected]
with:
dotnet-version: '6.0.x'

- name: Install dependencies
run: dotnet restore

- name: Build
run: dotnet build -c Release --no-restore
30 changes: 30 additions & 0 deletions .github/workflows/Release_Package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Upload dotnet package

on:
release:
types: [created]

jobs:
deploy:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x' # SDK Version to use.
source-url: https://nuget.pkg.github.com/PinchPayments/index.json
env:
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

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

- name: Create the package
run: dotnet pack --configuration Release

- name: Publish the package to GPR
working-directory: ./src/Pinch.SDK
run: dotnet nuget push ./bin/Release/*.nupkg
1 change: 0 additions & 1 deletion src/Pinch.SDK.WebSample/Pinch.SDK.WebSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<UserSecretsId>aspnet5-Pinch.SDK.WebSample-035714b9-1391-452f-876c-de29839a80c8</UserSecretsId>
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Pinch.SDK/Agreements/AgreementClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Pinch.SDK.Helpers;

namespace Pinch.SDK.Agreements
{
Expand Down Expand Up @@ -46,10 +47,9 @@ public async Task<ApiResponse<AgreementDetailed>> GetByAnonymousToken(string tok
/// </summary>
/// <param name="agreementId">Agreement ID</param>
/// <returns></returns>
public async Task<ApiResponse<Stream>> GetDdr(string agreementId)
public async Task<ApiResponse<FileDto>> GetDdr(string agreementId)
{
var response = await GetFile($"agreements/ddr/{agreementId}");

return response.ToApiResponse();
}

Expand Down
8 changes: 4 additions & 4 deletions src/Pinch.SDK/BaseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected async Task<QuickResponse<T>> GetHttp<T>(string url)
return await SendHttp<T>(() => new HttpRequestMessage(HttpMethod.Get, Options.BaseUri + url));
}

protected async Task<QuickFile> GetFile(string url)
protected async Task<QuickFileResponse> GetFile(string url)
{
return await SendHttpFile(() => new HttpRequestMessage(HttpMethod.Get, Options.BaseUri + url));
}
Expand Down Expand Up @@ -160,7 +160,7 @@ private async Task<QuickResponse<T, TOptions>> SendHttp<T, TOptions>(Func<HttpRe
}
}

private async Task<QuickFile> SendHttpFile(Func<HttpRequestMessage> requestFunc)
private async Task<QuickFileResponse> SendHttpFile(Func<HttpRequestMessage> requestFunc)
{
try
{
Expand All @@ -176,11 +176,11 @@ private async Task<QuickFile> SendHttpFile(Func<HttpRequestMessage> requestFunc)
response = await _httpClientFactory().SendAsync(request);
}

return await QuickFile.FromMessage(response);
return await QuickFileResponse.FromMessage(response);
}
catch (Exception ex)
{
return new QuickFile()
return new QuickFileResponse()
{
Errors = new List<ApiError>()
{
Expand Down
17 changes: 17 additions & 0 deletions src/Pinch.SDK/Helpers/FileDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Mime;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace Pinch.SDK.Helpers
{
public class FileDto
{
public Stream Stream { get; set; }
public string Filename { get; set; }
public string ContentType { get; set; }
}
}
32 changes: 24 additions & 8 deletions src/Pinch.SDK/Helpers/HttpClientHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Mime;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
Expand Down Expand Up @@ -59,10 +60,10 @@ public static async Task<ApiResponse<T>> Get<T>(this HttpClient client, string u
return qr.ToApiResponse();
}

public static async Task<ApiResponse> GetFile(this HttpClient client, string url)
public static async Task<ApiResponse<FileDto>> GetFile(this HttpClient client, string url)
{
var response = await client.GetAsync(url);
var qr = await QuickFile.FromMessage(response);
var qr = await QuickFileResponse.FromMessage(response);
return qr.ToApiResponse();
}

Expand Down Expand Up @@ -294,17 +295,32 @@ public class QuickResponse<T, TOptions> : QuickResponse<T>
}
}

public class QuickFile : QuickResponse<Stream>
public class QuickFileResponse : QuickResponse<FileDto>
{
public new static async Task<QuickFile> FromMessage(HttpResponseMessage message)
public new static async Task<QuickFileResponse> FromMessage(HttpResponseMessage message)
{
var response = new QuickFile();
response.Message = message;
response.ResponseBody = await message.Content.ReadAsStringAsync();
var response = new QuickFileResponse
{
Message = message
};

if (message.IsSuccessStatusCode)
{
response.Data = await message.Content.ReadAsStreamAsync();
response.Data = new FileDto()
{
Stream = await message.Content.ReadAsStreamAsync()
};

var header = message.Content.Headers.GetValues("content-disposition")?.ToList();
if (header != null && header.Any())
{
response.Data.Filename = new ContentDisposition(header.First()).FileName;
}
var contentTypeHeader = message.Content.Headers.GetValues("content-type")?.ToList();
if (contentTypeHeader != null && contentTypeHeader.Any())
{
response.Data.ContentType = contentTypeHeader.First();
}
}
else
{
Expand Down
12 changes: 0 additions & 12 deletions src/Pinch.SDK/Merchants/MerchantClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,6 @@ public async Task<ApiResponse<ManagedMerchant>> CreateManagedMerchant(ManagedMer
return response.ToApiResponse();
}

/// <summary>
/// Create a new verification session for the specified user.
/// </summary>
/// <param name="contactId">The contactID in `con_XXXXXXXX` format.</param>
/// <returns></returns>
public async Task<ApiResponse<VerificationSession>> CreateVerificationSession(string contactId)
{
var response = await PostHttp<VerificationSession>("merchants/verification-session", new { contactId });

return response.ToApiResponse();
}

/// <summary>
/// Upload documents for the merchant
/// </summary>
Expand Down
25 changes: 0 additions & 25 deletions src/Pinch.SDK/Merchants/VerificationSession.cs

This file was deleted.

8 changes: 2 additions & 6 deletions src/Pinch.SDK/Pinch.SDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Summary>The official Pinch Payments SDK</Summary>
<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>Ben Cull</Authors>
<Authors>Pinch Payments</Authors>
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Pinch.SDK</AssemblyName>
Expand All @@ -13,7 +13,7 @@
<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.19.3</Version>
<Version>0.20.0</Version>
</PropertyGroup>

<ItemGroup>
Expand All @@ -30,8 +30,4 @@
<Reference Include="System.ComponentModel.DataAnnotations" />
</ItemGroup>

<Target Name="PostcompileScript" AfterTargets="Build" Condition=" '$(IsCrossTargetingBuild)' != 'true' ">
<Exec Command="dotnet pack --no-build --configuration $(Configuration)" />
</Target>

</Project>
3 changes: 3 additions & 0 deletions src/Pinch.SDK/PinchApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Pinch.SDK.Payments;
using Pinch.SDK.Plans;
using Pinch.SDK.Refunds;
using Pinch.SDK.Statements;
using Pinch.SDK.Subscriptions;
using Pinch.SDK.Transfers;
using Pinch.SDK.Webhooks;
Expand Down Expand Up @@ -51,6 +52,7 @@ public class PinchApi
private FeesClient _fees;
private CustomerClient _customer;
private RefundsClient _refunds;
private StatementsClient _statements;

public AuthClient Auth => _auth ?? (_auth = new AuthClient(_secretKey, _options.AuthUri, _options.BaseUri, _options.AdditionalScopes, HttpClientFactoryOrStaticInstance()));
public MerchantClient Merchant => _merchant ?? (_merchant = new MerchantClient(_options, GetAccessToken, HttpClientFactoryOrStaticInstance()));
Expand All @@ -66,6 +68,7 @@ public class PinchApi
public FeesClient Fees => _fees ?? (_fees = new FeesClient(_options, GetAccessToken, HttpClientFactoryOrStaticInstance()));
public CustomerClient Customers => _customer ?? (_customer = new CustomerClient(_options, GetAccessToken, HttpClientFactoryOrStaticInstance()));
public RefundsClient Refunds => _refunds ?? (_refunds = new RefundsClient(_options, GetAccessToken, HttpClientFactoryOrStaticInstance()));
public StatementsClient Statements => _statements ?? (_statements = new StatementsClient(_options, GetAccessToken, HttpClientFactoryOrStaticInstance()));

/// <summary>
/// Supply your Merchant ID and Secret Key. These can be found in the API Keys menu item in the Pinch Portal.
Expand Down
23 changes: 23 additions & 0 deletions src/Pinch.SDK/Statements/DailyStatement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using Pinch.SDK.Payers;

namespace Pinch.SDK.Statements
{
public class DailyStatement
{
/// <summary>
/// The Daily Statement ID
/// </summary>
public string Id { get; set; }

/// <summary>
/// Status of the PDF generation.
/// </summary>
public string PdfGenerationStatus { get; set; }

/// <summary>
/// Date of the statement
/// </summary>
public string StatementDateLocal { get; set; }
}
}
29 changes: 29 additions & 0 deletions src/Pinch.SDK/Statements/MerchantInvoice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using Pinch.SDK.Payers;

namespace Pinch.SDK.Statements
{
public class MerchantInvoice
{
/// <summary>
/// The Merchant Invoice Id
/// </summary>
public string Id { get; set; }

/// <summary>
/// Invoice generation date.
/// </summary>
public string StatementDateLocal { get; set; }

/// <summary>
/// Start Date of the merchant invoice
/// </summary>
public string PeriodStartDateLocal { get; set; }


/// <summary>
/// End Date of the merchant invoice
/// </summary>
public string PeriodEndDateLocal { get; set; }
}
}
Loading

0 comments on commit 87835d7

Please sign in to comment.