Skip to content

Commit 6b5e4b0

Browse files
authored
Merge pull request #1 from alipay/v1
V1
2 parents 92d0674 + 0b9c6f1 commit 6b5e4b0

26 files changed

+1373
-0
lines changed

.gitignore

Lines changed: 405 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Alipay AMS(Alipay Merchant Services) C# Bindings
2+
3+
4+
## Documentation
5+
6+
Please see the [API docs](https://global.alipay.com/doc/ams) for the most up-to-date documentation.
7+
8+
## Usage
9+
10+
### Preparing
11+
12+
You need the following Integration information before starting:
13+
```
14+
clientId=your_client_id_here
15+
privateKey=your_private_key_here
16+
alipayPublicKey=your_public_key_here
17+
gatewayUrl=the_alipay_gateway_endpoint
18+
```
19+
20+
Please see the [developer docs](https://global.alipay.com/doc/ams_upm/introduction) for help with getting the above information.
21+
22+
see `./ams-dotnet/src/example/Program.cs` for more demo usage.
23+
24+
## Advanced Topic
25+
26+
### Integration Best Practice
27+
28+
Create optimal payment experiences for your customers by following these [best practices](https://global.alipay.com/doc/ams_upm/bp) for integrations.
29+
30+
### Using API Mock
31+
32+
We provide an API mocking tool(currently in BETA version) for you to easily test exceptional cases.
33+
34+
Below are some of the default out-of-box mocking rules that basically use the payment amount value to identify the desired mock response:
35+
36+
|API|when which input parameter|equals what|then you get a response of|
37+
|---|---|---|---|
38+
|ams/api/v1/payments/pay|payToAmount.value|9901|UNKNOWN_EXCEPTION|
39+
|ams/api/v1/payments/pay|payToAmount.value|9902|network timeout|
40+
|ams/api/v1/payments/inquiryPayment|payToAmount.value of the corresponding PAY request|9903|UNKNOWN_EXCEPTION|
41+
|ams/api/v1/payments/inquiryPayment|payToAmount.value of the corresponding PAY request|9904|network timeout|
42+
43+
To use this mocking tool:
44+
45+
1. Set gatewayUrl=https://isandbox.alipaydev.com
46+
2. Set alipayPublicKey to a fixed value that you can get from us through [email protected].
47+
48+
### Acceptance testing
49+
50+
Pass all the acceptance test cases in the Alipay Developer Center to ensure a high quality integration. Especially, test exceptions by using test cases.
51+
52+
## To get help
53+
54+
If you have any question or feedbacks regarding this sdk, please contact us at [email protected].
55+
56+
For other tech integration related issues, please reach us through [email protected].
57+
58+
59+
## FAQ
60+
61+
### What if I only need to use the digital signature feature ?
62+
63+
See [Digital signature](https://global.alipay.com/doc/ams/digital_signature) for details about the signature algorithm used for data transmission.
64+
65+
`./ams-dotnet/src/com/alipay/ams/util/SignatureUtil.cs` provides static utility methods that you can directly use.
66+
67+
## Change history
68+
69+
|Date|Version|Content|Backward compatible?|
70+
|---|---|---|---|
71+
|2020/10/10|1.0|v1 release|-|
72+

ams-dotnet/ams-dotnet.csproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
<RootNamespace>ams_dotnet</RootNamespace>
7+
<BaseDirectory>src</BaseDirectory>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<Folder Include="src\com\alipay\ams\api\request\" />
12+
<Folder Include="src\com\alipay\ams\api\response\" />
13+
<Folder Include="src\com\alipay\ams\api\entities\" />
14+
<Folder Include="src\com\alipay\ams\util\" />
15+
</ItemGroup>
16+
</Project>

ams-dotnet/ams-dotnet.sln

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ams-dotnet", "ams-dotnet.csproj", "{872BDA36-5AFB-4E4C-9FA4-30F829C7DD6F}"
5+
EndProject
6+
Global
7+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8+
Debug|Any CPU = Debug|Any CPU
9+
Release|Any CPU = Release|Any CPU
10+
EndGlobalSection
11+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
12+
{872BDA36-5AFB-4E4C-9FA4-30F829C7DD6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13+
{872BDA36-5AFB-4E4C-9FA4-30F829C7DD6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
14+
{872BDA36-5AFB-4E4C-9FA4-30F829C7DD6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
15+
{872BDA36-5AFB-4E4C-9FA4-30F829C7DD6F}.Release|Any CPU.Build.0 = Release|Any CPU
16+
EndGlobalSection
17+
EndGlobal
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Net.Http;
3+
using System.Text;
4+
using com.alipay.ams.api.response;
5+
6+
namespace com.alipay.ams.api
7+
{
8+
public class DefaultAlipayClient
9+
{
10+
public DefaultAlipayClient(
11+
string gatewayUrl,
12+
string clientId,
13+
string merchantPrivateKey,
14+
string alipayPublicKey,
15+
string agentToken = null)
16+
{
17+
this.AlipayPublicKey = alipayPublicKey;
18+
this.ClientId = clientId;
19+
this.AgentToken = agentToken;
20+
this.GatewayUrl = gatewayUrl;
21+
this.MerchantPrivateKey = merchantPrivateKey;
22+
}
23+
24+
public string GatewayUrl { get; }
25+
public string ClientId { get; }
26+
public string AgentToken { get; }
27+
public string MerchantPrivateKey { get; }
28+
public string AlipayPublicKey { get; }
29+
30+
private HttpClient client = new System.Net.Http.HttpClient();
31+
32+
public TAMSResponse Execute<TAMSResponse>(request.AMSRequest<TAMSResponse> request)
33+
where TAMSResponse : AMSResponse
34+
{
35+
36+
var requestMessage = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Post, this.GatewayUrl+ request.GetRequestURI());
37+
38+
var body = request.BuildBody();
39+
var headers = request.BuildRequestHeader(this.ClientId,this.AgentToken,this.MerchantPrivateKey);
40+
41+
42+
foreach (var header in headers)
43+
{
44+
requestMessage.Headers.Add(header.Key, header.Value);
45+
}
46+
47+
Console.WriteLine("Request --> " + body);
48+
requestMessage.Content = new ByteArrayContent(Encoding.UTF8.GetBytes(body));
49+
requestMessage.Content.Headers.Add("Content-Type", "application/json; charset=UTF-8");
50+
51+
52+
var ret = client.SendAsync(requestMessage).ConfigureAwait(false).GetAwaiter().GetResult(); ;
53+
54+
return AMSResponse.ParseResponse<TAMSResponse>(ret, request.GetRequestURI(), this.ClientId,this.AlipayPublicKey);
55+
}
56+
}
57+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace com.alipay.ams.api.entities
4+
{
5+
public class Amount
6+
{
7+
public Amount() { }
8+
9+
[JsonPropertyNameAttribute("currency")]
10+
public string Currency { get; set; }
11+
12+
[JsonPropertyNameAttribute("value")]
13+
public string Value { get; set; }
14+
15+
public Amount(string currency, string amountInCents)
16+
{
17+
this.Currency = currency;
18+
this.Value = amountInCents;
19+
}
20+
public Amount(string currency, long amountInCents)
21+
{
22+
this.Currency = currency;
23+
this.Value = amountInCents.ToString();
24+
}
25+
}
26+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Text.Json.Serialization;
3+
4+
namespace com.alipay.ams.api.entities
5+
{
6+
public class Env
7+
{
8+
public Env()
9+
{
10+
}
11+
12+
[JsonPropertyNameAttribute("storeTerminalId")]
13+
public string StoreTerminalId { get; internal set; }
14+
15+
[JsonPropertyNameAttribute("storeTerminalRequestTime")]
16+
public string StoreTerminalRequestTime { get; internal set; }
17+
}
18+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Text.Json.Serialization;
3+
4+
namespace com.alipay.ams.api.entities
5+
{
6+
public class Merchant
7+
{
8+
9+
public Merchant(string merchantName, string referenceMerchantId, string merchantMCC, Store store)
10+
{
11+
this.MerchantName = merchantName;
12+
this.ReferenceMerchantId = referenceMerchantId;
13+
this.MerchantMCC = merchantMCC;
14+
this.Store = store;
15+
}
16+
17+
[JsonPropertyNameAttribute("referenceMerchantId")]
18+
public string ReferenceMerchantId { get; internal set; }
19+
20+
[JsonPropertyNameAttribute("merchantMCC")]
21+
public string MerchantMCC { get; internal set; }
22+
23+
[JsonPropertyNameAttribute("merchantName")]
24+
public string MerchantName { get; internal set; }
25+
26+
[JsonPropertyNameAttribute("store")]
27+
public Store Store { get; internal set; }
28+
}
29+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace com.alipay.ams.api.entities
4+
{
5+
public class Order
6+
{
7+
[JsonPropertyNameAttribute("referenceOrderId")]
8+
public string ReferenceOrderId { get; set; }
9+
10+
[JsonPropertyNameAttribute("orderDescription")]
11+
public string OrderDescription { get; set; }
12+
13+
[JsonPropertyNameAttribute("orderAmount")]
14+
public Amount OrderAmount { get; set; }
15+
16+
[JsonPropertyNameAttribute("merchant")]
17+
public Merchant Merchant { get; set; }
18+
19+
[JsonPropertyNameAttribute("env")]
20+
public Env Env { get; set; }
21+
}
22+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Text.Json.Serialization;
3+
4+
namespace com.alipay.ams.api.entities
5+
{
6+
public class PspCustomerInfo
7+
{
8+
public PspCustomerInfo() { }
9+
10+
[JsonPropertyNameAttribute("displayCustomerId")]
11+
public string DisplayCustomerId { get; set; }
12+
13+
[JsonPropertyNameAttribute("pspCustomerId")]
14+
public string PspCustomerId { get; set; }
15+
16+
[JsonPropertyNameAttribute("pspName")]
17+
public string PspName { get; set; }
18+
19+
20+
}
21+
}

0 commit comments

Comments
 (0)