Skip to content

Commit 72ce552

Browse files
author
guangling.zgl
committed
Add samples and tests
1 parent 972a054 commit 72ce552

File tree

7 files changed

+610
-119
lines changed

7 files changed

+610
-119
lines changed

ams-dotnet/ams-dotnet.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
<Folder Include="src\com\alipay\ams\util\" />
1515
<Folder Include="src\com\alipay\ams\api\request\users\" />
1616
<Folder Include="src\com\alipay\ams\api\response\users\" />
17+
<Folder Include="src\example\tests\" />
1718
</ItemGroup>
1819
</Project>

ams-dotnet/src/com/alipay/ams/api/request/PaymentCreateRequest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class PaymentCreateRequest : AMSRequest<PaymentCreateResponse>
1111
{
1212

1313

14-
public string ProductCodeType { get; set; }
14+
public ProductCodeType ProductCode { get; set; }
1515

1616

1717
public string PaymentRequestId { get; set; }
@@ -36,7 +36,7 @@ public override string GetRequestURI()
3636
public override void validate()
3737
{
3838
Asserts.NotNull(PaymentRequestId, "paymentRequestId required.");
39-
Asserts.NotNull(ProductCodeType, "productCodeType required.");
39+
Asserts.NotNull(ProductCode, "productCode required.");
4040
Asserts.NotNull(PaymentAmount, "paymentAmount required.");
4141
Asserts.NotNull(Order, "order required.");
4242
Asserts.NotNull(PaymentRedirectUrl, "paymentRedirectUrl required.");

ams-dotnet/src/com/alipay/ams/api/request/auth/AlipayAuthApplyTokenRequest.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,23 @@ public override string GetRequestURI()
3030

3131
public override void validate()
3232
{
33-
Asserts.NotNull(AuthCode, "authCode required.");
33+
3434
Asserts.NotNull(CustomerBelongsTo, "customerBelongsTo required.");
3535
Asserts.NotNull(GrantType, "grantType required. ");
36+
37+
switch (GrantType)
38+
{
39+
case GrantType.AUTHORIZATION_CODE:
40+
Asserts.NotNull(AuthCode, "authCode required.");
41+
break;
42+
43+
case GrantType.REFRESH_TOKEN:
44+
Asserts.NotNull(RefreshToken, "refreshToken required.");
45+
break;
46+
47+
default:
48+
break;
49+
}
3650
}
3751
}
3852
}

ams-dotnet/src/example/Program.cs

Lines changed: 5 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
using System;
2-
using System.Text.Json;
1+
using ams_dotnet.example.tests;
32
using com.alipay.ams.api;
4-
using com.alipay.ams.api.entities;
5-
using com.alipay.ams.api.request;
63

74
namespace ams_dotnet
85
{
@@ -16,122 +13,14 @@ class Program
1613
private const string AlipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhJ5vPPThv5qFZ/3/nOcjJifbq9da9Yu1Xp3wSfJq2vFo0STtws6WGg1t34709Tcg7k4H4rgUnpvBX6h6gjGrFpZLt/uu7Q+cxnWjduvjXy4kanYp5pfSuZvblGR+LPB/yVQo0dh1iDAHk17GT1GuJ0MsBVGykU2Ji+PGkAFeYpaLiLl+uBtOEK8XVyxX7DSW8QNgQpaHBHrBBESqScV2O+ZyII6tVBlYBy/1QPkFDlJHSRTCQngak5HF0WSNYrPLFSMIgrmGDBfO2PFjuqStBNjL7+x9mRSzNF+3LY+uP/XemKmSTtRU5bSM99SNCHW5VGQvJuWX9P17686yRKKYOwIDAQAB";
1714

1815
static void Main(string[] args)
19-
{
20-
var client = new DefaultAlipayClient(GatewayUrl, ClientId, MerchantPrivateKey, AlipayPublicKey);
21-
22-
string paymentId = testInstorePayment(client);
23-
24-
//testQuery(client);
25-
26-
//testCancel(client);
27-
28-
//testCashierPayment(client);
29-
30-
//testRefund(client, paymentId);
31-
}
32-
33-
private static string testInstorePayment(DefaultAlipayClient client)
34-
{
35-
var request = new UserPresentedCodePaymentRequest("288888888888888888");
36-
37-
38-
long amountInCents = 1000;
39-
request.PaymentAmount = new Amount("JPY", amountInCents);
40-
Order order = new Order();
41-
order.OrderAmount = new Amount("JPY", amountInCents);
42-
order.OrderDescription = "New White Lace Sleeveless";
43-
order.ReferenceOrderId = "0000000001";
44-
order.Merchant = new Merchant("Some_Mer", "seller231117459", "7011", new Store(
45-
"Some_store", "store231117459", "7011"));
46-
47-
order.Env = new Env();
48-
order.Env.StoreTerminalId = "some_setStoreTerminalId";
49-
order.Env.StoreTerminalRequestTime = "2020-06-11T13:35:02+08:00";
50-
51-
string paymentRequestId = "PR20190000000001_" + (DateTime.Now - new DateTime(1970, 1, 1)).TotalMilliseconds;
52-
53-
request.PaymentRequestId = paymentRequestId;
54-
request.Order = order;
55-
56-
Console.WriteLine(request);
57-
58-
var response = client.Execute(request);
59-
60-
Console.WriteLine("\n============================================================\n");
61-
62-
Console.WriteLine(response);
63-
64-
return response.PaymentId;
65-
}
66-
67-
private static void testQuery(DefaultAlipayClient client)
6816
{
69-
PaymentInquiryRequest paymentInquiryRequest = new PaymentInquiryRequest();
70-
paymentInquiryRequest.PaymentRequestId = "PR20190000000001_575";
71-
72-
PaymentInquiryResponse paymentInquiryResponse = client.Execute(paymentInquiryRequest);
73-
74-
Console.WriteLine("paymentInquiryResponse: \n" + paymentInquiryResponse);
75-
}
76-
77-
private static void testCancel(DefaultAlipayClient client)
78-
{
79-
PaymentCancelRequest paymentCancelRequest = new PaymentCancelRequest();
80-
paymentCancelRequest.PaymentRequestId = "PR20190000000001_575";
81-
82-
PaymentCancelResponse paymentCancelResponse = client.Execute(paymentCancelRequest);
83-
84-
Console.WriteLine("paymentCancelResponse: \n" + paymentCancelResponse);
85-
}
86-
87-
private static void testRefund(DefaultAlipayClient client, string paymentId)
88-
{
89-
PaymentRefundRequest paymentRefundRequest = new PaymentRefundRequest();
90-
paymentRefundRequest.PaymentId = paymentId;
91-
paymentRefundRequest.RefundRequestId = "erf_PR20190000000001_575" + (DateTime.Now - new DateTime(1970, 1, 1)).TotalMilliseconds;
92-
paymentRefundRequest.RefundAmount = new Amount("JPY", 1000);
93-
paymentRefundRequest.RefundRequestTime = DateTime.UtcNow.ToString("o");
94-
95-
PaymentRefundResponse paymentRefundResponse = client.Execute(paymentRefundRequest);
96-
97-
Console.WriteLine("paymentRefundResponse: \n" + paymentRefundResponse);
98-
}
99-
100-
private static string testCashierPayment(DefaultAlipayClient client)
101-
{
102-
var request = new CommonPaymentRequest<CommonPaymentResponse>();
103-
104-
request.ProductCode = ProductCodeType.CASHIER_PAYMENT;
105-
request.PaymentAmount = new Amount("PHP", 300);
106-
request.PaymentMethod = new PaymentMethod(WalletPaymentMethodType.GCASH.ToString());
107-
request.PaymentNotifyUrl = "http://alipay.com";
108-
request.PaymentRedirectUrl = "http://alipay.com";
109-
110-
long amountInCents = 1000;
111-
Order order = new Order();
112-
order.OrderAmount = new Amount("PHP", amountInCents);
113-
order.OrderDescription = "New White Lace Sleeveless";
114-
order.ReferenceOrderId = "0000000001";
115-
order.Merchant = new Merchant("Some_Mer", "seller231117459", "7011", new Store(
116-
"Some_store", "store231117459", "7011"));
117-
118-
order.Env = new Env();
119-
order.Env.StoreTerminalId = "some_setStoreTerminalId";
120-
order.Env.StoreTerminalRequestTime = "2020-06-11T13:35:02+08:00";
12117

122-
string paymentRequestId = "PR20190000000001_" + (DateTime.Now - new DateTime(1970, 1, 1)).TotalMilliseconds;
123-
124-
request.PaymentRequestId = paymentRequestId;
125-
request.Order = order;
126-
127-
Console.WriteLine(request);
18+
//InstorePaymentTest.run(new DefaultAlipayClient(GatewayUrl, ClientId, MerchantPrivateKey, AlipayPublicKey), "SGD");
12819

129-
CommonPaymentResponse response = client.Execute(request);
130-
131-
Console.WriteLine("\n============================================================\n");
132-
Console.WriteLine(response);
20+
CashierPaymentTest.run(new DefaultAlipayClient(GatewayUrl, ClientId, MerchantPrivateKey, AlipayPublicKey), "PHP");
13321

134-
return response.PaymentId;
22+
//AutoDebitTest.run(new DefaultAlipayClient(GatewayUrl, ClientIdAD, MerchantPrivateKey, AlipayPublicKeyAD), "PHP");
23+
13524
}
13625
}
13726
}

0 commit comments

Comments
 (0)