From 3bc8d92f6e9138b6b7fdd42c02d0ea76dedf17d6 Mon Sep 17 00:00:00 2001 From: SergioRykov Date: Sat, 28 Nov 2015 21:42:46 +0300 Subject: [PATCH] README.md updated to show features of release 1.0.1 --- GlobalAssemblyInfo.cs | 5 +- README.md | 106 +++++++++++++++++- .../Platron.Client.Tests.csproj | 5 + Source/Platron.Client.Tests/ReadmeTests.cs | 77 +++++++++++++ Source/Platron.Client.Tests/packages.config | 1 + release.cmd | 12 ++ 6 files changed, 202 insertions(+), 4 deletions(-) create mode 100644 Source/Platron.Client.Tests/ReadmeTests.cs create mode 100644 release.cmd diff --git a/GlobalAssemblyInfo.cs b/GlobalAssemblyInfo.cs index e75b102..51c5860 100644 --- a/GlobalAssemblyInfo.cs +++ b/GlobalAssemblyInfo.cs @@ -11,8 +11,7 @@ [assembly: System.Reflection.AssemblyProduct("Platron API client")] [assembly: System.Reflection.AssemblyCopyright("Copyright © Sergio Rykov. Since 2015")] [assembly: System.Reflection.AssemblyConfiguration("Release")] -[assembly: System.Reflection.AssemblyVersion("1.0.2")] -[assembly: System.Reflection.AssemblyFileVersion("1.0.2")] -[assembly: System.Reflection.AssemblyInformationalVersion("Compiled By Sergio")] +[assembly: System.Reflection.AssemblyVersion("1.0.1")] +[assembly: System.Reflection.AssemblyFileVersion("1.0.1")] diff --git a/README.md b/README.md index 2873f4c..05799e7 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,112 @@ + # Platron.Client A Platron API client library for .NET. Based on API **version 3.5** ([EN](http://www.platron.ru/integration/Merchant_Platron_API_EN.pdf "Merchant_Platron_API_EN.pdf") | [RU](http://www.platron.ru/integration/Merchant_Platron_API_RU.pdf "Merchant_Platron_API_RU.pdf")) -[Documentation](http://platronclient.readthedocs.org/en/latest) +# Documentation +[http://platronclient.readthedocs.org/en/latest](http://platronclient.readthedocs.org/en/latest) # Getting started + +We will proceed showing how to process payment for order `#1234567890`. + +Client sends to server request to proceed order payment. Server initiates payment sending request to Platron. Platron can return html page to let server show it by itself or redirect url. We will use redirect url. + +If server knows user's phone number (and/or email) it can be added to request in order to simplify payment process for user. + +```csharp +var credentials = new Credentials("0000", "asdffsasdfasdfasdf"); +var client = new PlatronClient(credentials); + +// ensure that your server listens on that address and accepts GET request +var resultUrl = new Uri("https://my.server.com/platron/result"); + +var request = new InitPaymentRequest(1.Rur(), "Order payment") + { + OrderId = "#1234567890", + UserPhone = "+79990001112", + ResultUrl = resultUrl + }; + +InitPaymentResponse response = await client.InitPaymentAsync(request).ConfigureAwait(false); +await SendToUserAsync(response.RedirectUrl).ConfigureAwait(false); +``` + +User (or your client) opens link and proceed payment in browser. Platron sends request to ResultUrl GET with details of payment and awaits completing the order. + +We will show how to work with server side processing using simple but complete server on [Nancy](http://nancyfx.org). + +We will not cover hosting and bootstrapping details, the only important thing here is base address of our server: + +```csharp +WebApp.Start($"https://my.server.com"); +``` + +Server accepts ResultUrl and can return OK, Error or Rejected response back to Platron. There is ResultUrl processing module: + +```csharp +public sealed class PlatronModule : NancyModule +{ + private readonly PlatronClient _platronClient; + + public PlatronModule(PlatronClient platronClient) + { + // IoC container will make us super-duper happy and gives us a client. + _platronClient = platronClient; + + Get["/platron/result", true] = async (_, ct) => + { + CallbackResponse response = await CompleteOrderAsync(Request.Url); + return AsXml(response); + }; + } + + private async Task CompleteOrderAsync(Uri resultUrl) + { + ResultUrlRequest request = _platronClient.ResultUrl.Parse(resultUrl); + CallbackResponse response = _platronClient.ResultUrl.ReturnOk(request, "Order completed"); + return await Task.FromResult(response); + } + + private Response AsXml(CallbackResponse response) + { + return new Response + { + ContentType = "application/xml; charset:utf-8", + Contents = stream => + { + var data = Encoding.UTF8.GetBytes(response.Content); + stream.Write(data, 0, data.Length); + }, + StatusCode = (HttpStatusCode) System.Net.HttpStatusCode.OK + }; + } +} +``` + + +# Building + +If you don't have installed VS extension NuGet Package Manager, then install it or just execute `restore.cmd`. + +Open solution `Source\Platron.sln` and build it. + +# Testing + +Tests separated into several categories. + +`Integration` and `Manual` tests requires real credentials. You need to set them in environment variables: + + PLATRON_MERCHANTID=1234 + PLATRON_SECRETKEY=erwer87werwer8wer6 + PLATRON_PHONENUMBER=+79990001112 + +`Manual` tests ignored by default - they require interraption of test to fullfill - guess what :) - manual action like proceeding real payment for 1 ruble using your preferred payment system and then rejecting it by emulator of shop server. Platron has testing payment systems but you cann't complete scenario with it and receive confirmation ResultUrl callback from Platron. + +# Release + +To issue release `vX.Y.Z` execute + + release.cmd X.Y.Z +and take packages from `out\Release\Packages`. It's that simple. \ No newline at end of file diff --git a/Source/Platron.Client.Tests/Platron.Client.Tests.csproj b/Source/Platron.Client.Tests/Platron.Client.Tests.csproj index 426a85e..8e06aa4 100644 --- a/Source/Platron.Client.Tests/Platron.Client.Tests.csproj +++ b/Source/Platron.Client.Tests/Platron.Client.Tests.csproj @@ -35,6 +35,10 @@ ..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll True + + ..\packages\Nancy.1.4.2\lib\net40\Nancy.dll + True + @@ -61,6 +65,7 @@ + diff --git a/Source/Platron.Client.Tests/ReadmeTests.cs b/Source/Platron.Client.Tests/ReadmeTests.cs new file mode 100644 index 0000000..09b71d2 --- /dev/null +++ b/Source/Platron.Client.Tests/ReadmeTests.cs @@ -0,0 +1,77 @@ +using System; +using System.Text; +using System.Threading.Tasks; +using Nancy; +using Platron.Client.Extensions; +using Platron.Client.Http.Callbacks; +using Platron.Client.TestKit.Emulators; +using Xunit; + +namespace Platron.Client.Tests +{ + public sealed class ReadmeTests + { + [Fact(Skip = "Used in readme.md")] + public async Task GettingStarted_SampleClient_Succeeds() + { + var credentials = new Credentials("0000", "asdffsasdfasdfasdf"); + var client = new PlatronClient(credentials); + + // ensure that your server listens on that address and accepts GET request + var resultUrl = new Uri("https://my.server.com/platron/result"); + + var request = new InitPaymentRequest(1.Rur(), "Order payment") + { + OrderId = "#1234567890", + UserPhone = "+79990001112", + ResultUrl = resultUrl + }; + + InitPaymentResponse response = await client.InitPaymentAsync(request).ConfigureAwait(false); + await SendToUserAsync(response.RedirectUrl).ConfigureAwait(false); + } + + private async Task SendToUserAsync(Uri payment) + { + await Task.Delay(TimeSpan.FromMilliseconds(10)); + } + + public sealed class PlatronModule : NancyModule + { + private readonly PlatronClient _platronClient; + + public PlatronModule(PlatronClient platronClient) + { + // IoC container will make us super-duper happy and gives us a client. + _platronClient = platronClient; + + Get["/platron/result", true] = async (_, ct) => + { + CallbackResponse response = await CompleteOrderAsync(Request.Url); + return AsXml(response); + }; + } + + private async Task CompleteOrderAsync(Uri resultUrl) + { + ResultUrlRequest request = _platronClient.ResultUrl.Parse(resultUrl); + CallbackResponse response = _platronClient.ResultUrl.ReturnOk(request, "Order completed"); + return await Task.FromResult(response); + } + + private Response AsXml(CallbackResponse response) + { + return new Response + { + ContentType = "application/xml; charset:utf-8", + Contents = stream => + { + var data = Encoding.UTF8.GetBytes(response.Content); + stream.Write(data, 0, data.Length); + }, + StatusCode = (HttpStatusCode) System.Net.HttpStatusCode.OK + }; + } + } + } +} \ No newline at end of file diff --git a/Source/Platron.Client.Tests/packages.config b/Source/Platron.Client.Tests/packages.config index e0d64f5..f6e34ea 100644 --- a/Source/Platron.Client.Tests/packages.config +++ b/Source/Platron.Client.Tests/packages.config @@ -1,6 +1,7 @@  + diff --git a/release.cmd b/release.cmd new file mode 100644 index 0000000..73cfeb5 --- /dev/null +++ b/release.cmd @@ -0,0 +1,12 @@ +set RELEASEVERSION=%1 + +call restore.cmd + +rem as TeamCity set +set BUILD_NUMBER=%RELEASEVERSION% + +set BuildVersion=%RELEASEVERSION% +msbuild root.msbuild + +set PackageVersion=%RELEASEVERSION% +msbuild nuget.msbuild \ No newline at end of file