Skip to content

Commit 972a054

Browse files
author
guangling.zgl
committed
UserPresentedCodePaymentRequest refactored
1 parent 7f1ea82 commit 972a054

File tree

4 files changed

+74
-94
lines changed

4 files changed

+74
-94
lines changed

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

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,44 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Text.Json;
4-
using System.Text.Json.Serialization;
52
using com.alipay.ams.api.entities;
63
using com.alipay.ams.util;
74

85
namespace com.alipay.ams.api.request
96
{
10-
public class CommonPaymentRequest : AMSRequest<CommonPaymentResponse>
7+
public class CommonPaymentRequest<TCommonPaymentResponse> : AMSRequest<TCommonPaymentResponse>
8+
where TCommonPaymentResponse : CommonPaymentResponse
119
{
1210
public ProductCodeType ProductCode { get; set; }
13-
14-
11+
1512
public string PaymentRequestId { get; set; }
1613

17-
1814
public Order Order { get; set; }
1915

20-
2116
public Amount PaymentAmount { get; set; }
2217

23-
2418
public PaymentMethod PayToMethod { get; set; }
2519

26-
2720
public PaymentMethod PaymentMethod { get; set; }
2821

29-
3022
public string PaymentExpiryTime { get; set; }
3123

32-
3324
public string PaymentRedirectUrl { get; set; }
3425

35-
3626
public string PaymentNotifyUrl { get; set; }
3727

38-
3928
public Boolean IsAuthorization { get; set; }
4029

41-
4230
public PaymentVerificationData PaymentVerificationData { get; set; }
4331

44-
4532
public PaymentFactor PaymentFactor { get; set; }
4633

47-
4834
public Merchant Merchant { get; set; }
4935

50-
5136
public Env Env { get; set; }
5237

53-
5438
public SettlementStrategy SettlementStrategy { get; set; }
5539

56-
5740
public string ExtendInfo { get; set; }
5841

59-
6042
public CreditPayPlan CreditPayPlan { get; set; }
6143

6244
public override string GetRequestURI()

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

Lines changed: 9 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,29 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Text.Json;
4+
using System.Text.Json.Serialization;
45
using com.alipay.ams.api.entities;
56
using com.alipay.ams.util;
67

78
namespace com.alipay.ams.api.request
89
{
9-
public class UserPresentedCodePaymentRequest : AMSRequest<UserPresentedCodePaymentResponse>
10+
public class UserPresentedCodePaymentRequest : CommonPaymentRequest<UserPresentedCodePaymentResponse>
1011
{
1112

12-
public string PaymentRequestId { get; set; }
13-
public entities.Order Order { get; set; }
14-
public string Currency { get; set; }
15-
public long AmountInCents { get; set; }
16-
public string PaymentCode { get; set; }
17-
public string PaymentNotifyUrl { get; set; }
18-
public DateTime PaymentExpiryTime { get; set; }
19-
20-
21-
22-
public override string BuildBody()
13+
public UserPresentedCodePaymentRequest(string paymentCode)
2314
{
15+
this.ProductCode = ProductCodeType.IN_STORE_PAYMENT;
16+
this.PaymentMethod = new PaymentMethod(WalletPaymentMethodType.CONNECT_WALLET.ToString());
17+
this.PaymentFactor = new PaymentFactor();
18+
this.PaymentFactor.InStorePaymentScenario = InStorePaymentScenario.PaymentCode;
2419

25-
validate();
26-
27-
var body = new Dictionary<string,object>();
28-
29-
body.Add("productCode", "IN_STORE_PAYMENT");
30-
body.Add("paymentRequestId", PaymentRequestId);
31-
32-
body.Add("order", Order);
33-
34-
if (PaymentNotifyUrl != null)
35-
{
36-
body.Add("paymentNotifyUrl", PaymentNotifyUrl);
37-
}
38-
39-
if (PaymentExpiryTime != null)
40-
{
41-
body.Add("paymentExpiryTime", PaymentExpiryTime.ToString("o"));
42-
}
43-
44-
var paymentAmount = new Amount(Currency, AmountInCents);
45-
body.Add("paymentAmount", paymentAmount);
46-
47-
var paymentMethod = new Dictionary<String, String>();
48-
paymentMethod.Add("paymentMethodType", "CONNECT_WALLET");
49-
paymentMethod.Add("paymentMethodId", PaymentCode);
50-
body.Add("paymentMethod", paymentMethod);
51-
52-
var paymentFactor = new Dictionary<String, Object>();
53-
paymentFactor.Add("inStorePaymentScenario", "PaymentCode");
54-
body.Add("paymentFactor", paymentFactor);
55-
56-
57-
return JsonSerializer.Serialize(body);
58-
}
59-
60-
public override string GetRequestURI()
61-
{
62-
return "/ams/api/v1/payments/pay";
20+
this.PaymentMethod.PaymentMethodId = paymentCode;
6321
}
6422

6523
public override void validate()
6624
{
6725
Asserts.NotNull(PaymentRequestId, "paymentRequestId required.");
68-
Asserts.NotNull(PaymentCode, "paymentCode required.");
69-
Asserts.NotNull(Currency, "currency required.");
70-
Asserts.NotNull(AmountInCents, "amountInCents required.");
26+
Asserts.NotNull(PaymentAmount, "paymentAmount required.");
7127
Asserts.NotNull(Order, "order required.");
7228
Asserts.NotNull(Order.Merchant, "order.merchant required.");
7329
Asserts.NotNull(Order.OrderAmount, "order.orderAmount required.");

ams-dotnet/src/com/alipay/ams/api/response/UserPresentedCodePaymentResponse.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,32 @@
77

88
namespace com.alipay.ams.api.request
99
{
10-
public class UserPresentedCodePaymentResponse : AMSResponse
10+
public class UserPresentedCodePaymentResponse : CommonPaymentResponse
1111
{
1212

1313

14-
public Amount ActualPaymentAmount { get; set; }
14+
public new Amount ActualPaymentAmount { get; set; }
1515

1616

17-
public Amount PaymentAmount { get; set; }
17+
public new Amount PaymentAmount { get; set; }
1818

1919

20-
public string PaymentCreateTime { get; set; }
20+
public new string PaymentCreateTime { get; set; }
2121

2222

23-
public string PaymentId { get; set; }
23+
public new string PaymentId { get; set; }
2424

2525

26-
public Quote PaymentQuote { get; set; }
26+
public new Quote PaymentQuote { get; set; }
2727

2828

29-
public string PaymentRequestId { get; set; }
29+
public new string PaymentRequestId { get; set; }
3030

3131

32-
public string PaymentTime { get; set; }
32+
public new string PaymentTime { get; set; }
3333

3434

35-
public PspCustomerInfo PspCustomerInfo { get; set; }
35+
public new PspCustomerInfo PspCustomerInfo { get; set; }
3636

3737
}
3838
}

ams-dotnet/src/example/Program.cs

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Text.Json;
23
using com.alipay.ams.api;
34
using com.alipay.ams.api.entities;
45
using com.alipay.ams.api.request;
@@ -18,20 +19,24 @@ static void Main(string[] args)
1819
{
1920
var client = new DefaultAlipayClient(GatewayUrl, ClientId, MerchantPrivateKey, AlipayPublicKey);
2021

21-
string paymentId = testPay(client);
22+
string paymentId = testInstorePayment(client);
2223

2324
//testQuery(client);
2425

2526
//testCancel(client);
2627

27-
testRefund(client, paymentId);
28+
//testCashierPayment(client);
29+
30+
//testRefund(client, paymentId);
2831
}
2932

30-
private static string testPay(DefaultAlipayClient client)
33+
private static string testInstorePayment(DefaultAlipayClient client)
3134
{
32-
var request = new UserPresentedCodePaymentRequest();
35+
var request = new UserPresentedCodePaymentRequest("288888888888888888");
36+
3337

3438
long amountInCents = 1000;
39+
request.PaymentAmount = new Amount("JPY", amountInCents);
3540
Order order = new Order();
3641
order.OrderAmount = new Amount("JPY", amountInCents);
3742
order.OrderDescription = "New White Lace Sleeveless";
@@ -44,17 +49,17 @@ private static string testPay(DefaultAlipayClient client)
4449
order.Env.StoreTerminalRequestTime = "2020-06-11T13:35:02+08:00";
4550

4651
string paymentRequestId = "PR20190000000001_" + (DateTime.Now - new DateTime(1970, 1, 1)).TotalMilliseconds;
47-
string buyerPaymentCode = "288888888888888888";
4852

4953
request.PaymentRequestId = paymentRequestId;
50-
request.PaymentCode = buyerPaymentCode;
51-
request.Order = order;
52-
request.Currency = "JPY";
53-
request.AmountInCents = amountInCents;
54+
request.Order = order;
55+
56+
Console.WriteLine(request);
5457

55-
UserPresentedCodePaymentResponse response = client.Execute(request);
58+
var response = client.Execute(request);
5659

57-
Console.WriteLine("response: \n" + response);
60+
Console.WriteLine("\n============================================================\n");
61+
62+
Console.WriteLine(response);
5863

5964
return response.PaymentId;
6065
}
@@ -91,5 +96,42 @@ private static void testRefund(DefaultAlipayClient client, string paymentId)
9196

9297
Console.WriteLine("paymentRefundResponse: \n" + paymentRefundResponse);
9398
}
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";
121+
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);
128+
129+
CommonPaymentResponse response = client.Execute(request);
130+
131+
Console.WriteLine("\n============================================================\n");
132+
Console.WriteLine(response);
133+
134+
return response.PaymentId;
135+
}
94136
}
95137
}

0 commit comments

Comments
 (0)