Skip to content

Commit

Permalink
README.md updated to show features of release 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiorykov committed Nov 28, 2015
1 parent 4c9bd43 commit 3bc8d92
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 4 deletions.
5 changes: 2 additions & 3 deletions GlobalAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]


106 changes: 105 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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<Startup>($"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<CallbackResponse> 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.
5 changes: 5 additions & 0 deletions Source/Platron.Client.Tests/Platron.Client.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
<HintPath>..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Nancy, Version=1.4.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Nancy.1.4.2\lib\net40\Nancy.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
Expand All @@ -61,6 +65,7 @@
<Compile Include="InitPaymentTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Clients\ResultUrlClientTests.cs" />
<Compile Include="ReadmeTests.cs" />
<Compile Include="Samples.cs" />
<Compile Include="SettingsStorage.cs" />
</ItemGroup>
Expand Down
77 changes: 77 additions & 0 deletions Source/Platron.Client.Tests/ReadmeTests.cs
Original file line number Diff line number Diff line change
@@ -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<CallbackResponse> 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
};
}
}
}
}
1 change: 1 addition & 0 deletions Source/Platron.Client.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Moq" version="4.2.1510.2205" targetFramework="net452" />
<package id="Nancy" version="1.4.2" targetFramework="net452" />
<package id="xunit" version="2.1.0" targetFramework="net452" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net452" />
<package id="xunit.assert" version="2.1.0" targetFramework="net452" />
Expand Down
12 changes: 12 additions & 0 deletions release.cmd
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3bc8d92

Please sign in to comment.