Skip to content

Commit eaf0211

Browse files
authored
Add new payment params to Credit Card and Apple Pay (#21)
Add new payment parameters to Credit Card and Apple Pay sources
1 parent d98599d commit eaf0211

15 files changed

+87
-60
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2016 Moyasar
3+
Copyright (c) 2021 Moyasar
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Moyasar/Models/ApplePayMethod.cs

+6
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,11 @@ public class ApplePayMethod : IPaymentMethod
2323

2424
[JsonProperty("message")]
2525
public string Message { get; set; }
26+
27+
[JsonProperty("gateway_id")]
28+
public string GatewayId { get; set; }
29+
30+
[JsonProperty("reference_number")]
31+
public string ReferenceNumber { get; set; }
2632
}
2733
}

Moyasar/Models/CreditCard.cs

+12-6
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,26 @@ public class CreditCard : IPaymentMethod
1010
{
1111
[JsonProperty("type")]
1212
public string Type { get; }
13-
13+
1414
[JsonProperty("company")]
1515
public string Company { get; set; }
16-
16+
1717
[JsonProperty("name")]
1818
public string Name { get; set; }
19-
19+
2020
[JsonProperty("number")]
2121
public string Number { get; set; }
22-
22+
2323
[JsonProperty("message")]
2424
public string Message { get; set; }
25-
25+
2626
[JsonProperty("transaction_url")]
27-
public string TransactionUrl { get; set; }
27+
public string TransactionUrl { get; set; }
28+
29+
[JsonProperty("gateway_id")]
30+
public string GatewayId { get; set; }
31+
32+
[JsonProperty("reference_number")]
33+
public string ReferenceNumber { get; set; }
2834
}
2935
}

Moyasar/Moyasar.csproj

+7-16
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net40;net45;net451;net452;net46;net461;netstandard2.0</TargetFrameworks>
5-
<PackageVersion>2.2.0</PackageVersion>
4+
<TargetFrameworks>net40;net45;net451;net452;net46;net461;netstandard2.0;netstandard2.1</TargetFrameworks>
5+
<PackageVersion>2.3.0</PackageVersion>
66
<Title>Moyasar API's .NET Wrapper</Title>
77
<Authors>Ali Alhoshaiyan, Moyasar Dev Team</Authors>
8-
<Copyright>Copyright © 2019 Moyasar. All rights reserved</Copyright>
8+
<Copyright>Copyright © 2021 Moyasar. All rights reserved</Copyright>
99
<PackageProjectUrl>https://moyasar.com/</PackageProjectUrl>
1010
<PackageTags>Moyasar;API;Payment;CreditCard;Sadad;Mada</PackageTags>
1111
<PackageIcon>package-icon.png</PackageIcon>
@@ -14,27 +14,18 @@
1414
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1515
<PackageLicenseFile>LICENSE</PackageLicenseFile>
1616
<LangVersion>8</LangVersion>
17-
<AssemblyVersion>2.2.0</AssemblyVersion>
18-
<FileVersion>2.2.0</FileVersion>
17+
<AssemblyVersion>2.3.0</AssemblyVersion>
18+
<FileVersion>2.3.0</FileVersion>
1919
</PropertyGroup>
2020

2121
<ItemGroup>
22-
<Reference Include="Microsoft.CSharp" Condition="'$(TargetFramework)' == 'net40'" />
23-
<Reference Include="Microsoft.CSharp" Condition="'$(TargetFramework)' == 'net45'" />
24-
<Reference Include="Microsoft.CSharp" Condition="'$(TargetFramework)' == 'net451'" />
25-
<Reference Include="Microsoft.CSharp" Condition="'$(TargetFramework)' == 'net452'" />
26-
<Reference Include="Microsoft.CSharp" Condition="'$(TargetFramework)' == 'net46'" />
27-
<Reference Include="Microsoft.CSharp" Condition="'$(TargetFramework)' == 'net461'" />
28-
</ItemGroup>
29-
30-
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
31-
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
22+
<Reference Include="Microsoft.CSharp" />
3223
</ItemGroup>
3324

3425
<ItemGroup>
3526
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
3627
</ItemGroup>
37-
28+
3829
<ItemGroup>
3930
<None Include="..\LICENSE" Pack="true" PackagePath="" />
4031
<None Include="package-icon.png" Pack="true" PackagePath="" />

MoyasarTest/Fixtures/ApplePay/Failed.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
"company": "visa",
2121
"name": null,
2222
"number": "XXXX-XXXX-XXXX-1111",
23-
"message": "Expired token"
23+
"message": "Expired token",
24+
"gateway_id": "moyasar_ap_je1iUidxhrh74257S891wvW",
25+
"reference_number": "125478454231"
2426
},
2527
"metadata": {
2628
"order_id": "5ccfc0a4-b43b-437b-ab44-0ffdcf5755d8",

MoyasarTest/Fixtures/ApplePay/Paid.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
"company": "visa",
2121
"name": null,
2222
"number": "XXXX-XXXX-XXXX-1111",
23-
"message": "APPROVED"
23+
"message": "APPROVED",
24+
"gateway_id": "moyasar_ap_je1iUidxhrh74257S891wvW",
25+
"reference_number": "125478454231"
2426
},
2527
"metadata": {
2628
"order_id": "a2620c7d-658e-4c27-aa78-bc6532549cec",

MoyasarTest/Fixtures/CreditCard/Initiated.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
"name": "Long John",
2222
"number": "XXXX-XXXX-XXXX-1111",
2323
"message": null,
24-
"transaction_url": "https://api.moyasar.com/v1/transaction_auths/a9a6c4c9-b065-48c6-952a-184266ec4b4a/form?token=auth_n7FoPBZo2cYriecyZvzmXrXTP13E7og9HC3jGFDYqzF"
24+
"transaction_url": "https://api.moyasar.com/v1/transaction_auths/a9a6c4c9-b065-48c6-952a-184266ec4b4a/form?token=auth_n7FoPBZo2cYriecyZvzmXrXTP13E7og9HC3jGFDYqzF",
25+
"gateway_id": "moyasar_ap_je1iUidxhrh74257S891wvW",
26+
"reference_number": "125478454231"
2527
},
2628
"metadata": {
2729
"order_id": "fcd546c9-9b1d-446f-b48f-8667daae51b7",

MoyasarTest/Fixtures/CreditCard/Paid.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
"name": "Long John",
2222
"number": "XXXX-XXXX-XXXX-1111",
2323
"message": "APPROVED",
24-
"transaction_url": "https://api.moyasar.com/v1/transaction_auths/a9a6c4c9-b065-48c6-952a-184266ec4b4a/form?token=auth_n7FoPBZo2cYriecyZvzmXrXTP13E7og9HC3jGFDYqzF"
24+
"transaction_url": "https://api.moyasar.com/v1/transaction_auths/a9a6c4c9-b065-48c6-952a-184266ec4b4a/form?token=auth_n7FoPBZo2cYriecyZvzmXrXTP13E7og9HC3jGFDYqzF",
25+
"gateway_id": "moyasar_ap_je1iUidxhrh74257S891wvW",
26+
"reference_number": "125478454231"
2527
},
2628
"metadata": {
2729
"order_id": "5c02ba44-7fd1-444c-b82b-d3993b87d4b0",

MoyasarTest/Fixtures/CreditCard/Refunded.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
"name": "Long John",
2222
"number": "XXXX-XXXX-XXXX-1111",
2323
"message": "APPROVED",
24-
"transaction_url": "https://api.moyasar.com/v1/transaction_auths/a9a6c4c9-b065-48c6-952a-184266ec4b4a/form?token=auth_n7FoPBZo2cYriecyZvzmXrXTP13E7og9HC3jGFDYqzF"
24+
"transaction_url": "https://api.moyasar.com/v1/transaction_auths/a9a6c4c9-b065-48c6-952a-184266ec4b4a/form?token=auth_n7FoPBZo2cYriecyZvzmXrXTP13E7og9HC3jGFDYqzF",
25+
"gateway_id": "moyasar_ap_je1iUidxhrh74257S891wvW",
26+
"reference_number": "125478454231"
2527
},
2628
"metadata": {
2729
"order_id": "5c02ba44-7fd1-444c-b82b-d3993b87d4b0",

MoyasarTest/Fixtures/Invoice/Paid.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
"company": "visa",
3535
"name": null,
3636
"number": "XXXX-XXXX-XXXX-1111",
37-
"message": "APPROVED"
37+
"message": "APPROVED",
38+
"gateway_id": "moyasar_ap_je1iUidxhrh74257S891wvW",
39+
"reference_number": "125478454231",
3840
}
3941
}
4042
],

MoyasarTest/Fixtures/PaymentList.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
"name": "Long John",
3131
"number": "XXXX-XXXX-XXXX-1111",
3232
"message": "APPROVED",
33-
"transaction_url": "https://api.moyasar.com/v1/transaction_auths/a9a6c4c9-b065-48c6-952a-184266ec4b4a/form?token=auth_n7FoPBZo2cYriecyZvzmXrXTP13E7og9HC3jGFDYqzF"
33+
"transaction_url": "https://api.moyasar.com/v1/transaction_auths/a9a6c4c9-b065-48c6-952a-184266ec4b4a/form?token=auth_n7FoPBZo2cYriecyZvzmXrXTP13E7og9HC3jGFDYqzF",
34+
"gateway_id": "moyasar_ap_je1iUidxhrh74257S891wvW",
35+
"reference_number": "125478454231",
3436
},
3537
"metadata": {
3638
"order_id": "5c02ba44-7fd1-444c-b82b-d3993b87d4b0",
@@ -59,7 +61,9 @@
5961
"company": "visa",
6062
"name": null,
6163
"number": "XXXX-XXXX-XXXX-1111",
62-
"message": "APPROVED"
64+
"message": "APPROVED",
65+
"gateway_id": "moyasar_ap_je1iUidxhrh74257S891wvW",
66+
"reference_number": "125478454231"
6367
},
6468
"metadata": {
6569
"order_id": "a2620c7d-658e-4c27-aa78-bc6532549cec",
@@ -98,4 +102,4 @@
98102
}
99103
}
100104
]
101-
}
105+
}

MoyasarTest/Fixtures/Source/ApplePay.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
"company": "visa",
44
"name": null,
55
"number": "XXXX-XXXX-XXXX-1111",
6-
"message": "APPROVED"
6+
"message": "APPROVED",
7+
"gateway_id": "moyasar_ap_je1iUidxhrh74257S891wvW",
8+
"reference_number": "125478454231",
79
}

MoyasarTest/Fixtures/Source/CreditCard.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
"name": "Long John",
55
"number": "XXXX-XXXX-XXXX-1111",
66
"message": null,
7-
"transaction_url": "https://api.moyasar.com/v1/transaction_auths/a9a6c4c9-b065-48c6-952a-184266ec4b4a/form?token=auth_n7FoPBZo2cYriecyZvzmXrXTP13E7og9HC3jGFDYqzF"
7+
"transaction_url": "https://api.moyasar.com/v1/transaction_auths/a9a6c4c9-b065-48c6-952a-184266ec4b4a/form?token=auth_n7FoPBZo2cYriecyZvzmXrXTP13E7og9HC3jGFDYqzF",
8+
"gateway_id": "moyasar_ap_je1iUidxhrh74257S891wvW",
9+
"reference_number": "125478454231",
810
}

MoyasarTest/MoyasarTest.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<IsPackable>false</IsPackable>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<TargetFramework>net5.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>

MoyasarTest/PaymentTest.cs

+29-25
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ public async void TestPaymentInfoValidationRules()
2828
info.Validate();
2929
info.Amount = -1;
3030
await Assert.ThrowsAsync<ValidationException>(async () => await Task.Run(() => info.Validate()));
31-
31+
3232
info = GetValidPaymentInfo();
3333
info.Validate();
3434
info.Source = null;
3535
await Assert.ThrowsAsync<ValidationException>(async () => await Task.Run(() => info.Validate()));
36-
36+
3737
info = GetValidPaymentInfo();
3838
info.Validate();
3939
info.CallbackUrl = "hey";
@@ -47,26 +47,26 @@ public async void TestCcSourceValidationRules()
4747
source.Validate();
4848
source.Name = "";
4949
await Assert.ThrowsAsync<ValidationException>(async () => await Task.Run(() => source.Validate()));
50-
50+
5151
source = GetValidCcSource();
5252
source.Validate();
5353
source.Number = "";
5454
await Assert.ThrowsAsync<ValidationException>(async () => await Task.Run(() => source.Validate()));
55-
55+
5656
source = GetValidCcSource();
5757
source.Validate();
5858
source.Cvc = 0;
5959
await Assert.ThrowsAsync<ValidationException>(async () => await Task.Run(() => source.Validate()));
6060
source.Cvc = 1000;
6161
await Assert.ThrowsAsync<ValidationException>(async () => await Task.Run(() => source.Validate()));
62-
62+
6363
source = GetValidCcSource();
6464
source.Validate();
6565
source.Month = 0;
6666
await Assert.ThrowsAsync<ValidationException>(async () => await Task.Run(() => source.Validate()));
6767
source.Month = 13;
6868
await Assert.ThrowsAsync<ValidationException>(async () => await Task.Run(() => source.Validate()));
69-
69+
7070
source = GetValidCcSource();
7171
source.Validate();
7272
source.Year = -1;
@@ -77,7 +77,7 @@ public async void TestCcSourceValidationRules()
7777
public void TestDeserializingPayment()
7878
{
7979
ServiceMockHelper.MockJsonResponse("Fixtures/CreditCard/Paid.json");
80-
80+
8181
var payment = Payment.Fetch("b6c01c90-a091-45a4-9358-71668ecbf7ea");
8282
Assert.Equal("b6c01c90-a091-45a4-9358-71668ecbf7ea", payment.Id);
8383
Assert.Equal(1000, payment.Amount);
@@ -86,44 +86,48 @@ public void TestDeserializingPayment()
8686
Assert.Equal("https://mystore.com/order/redirect-back", payment.CallbackUrl);
8787
Assert.Equal("5c02ba44-7fd1-444c-b82b-d3993b87d4b0", payment.Metadata["order_id"]);
8888
Assert.Equal("50", payment.Metadata["tax"]);
89-
89+
9090
Assert.IsType<CreditCard>(payment.Source);
9191
var ccSource = (CreditCard) payment.Source;
92-
92+
9393
Assert.Equal("Long John", ccSource.Name);
9494
Assert.Equal("XXXX-XXXX-XXXX-1111", ccSource.Number);
95+
Assert.Equal("moyasar_ap_je1iUidxhrh74257S891wvW", ccSource.GatewayId);
96+
Assert.Equal("125478454231", ccSource.ReferenceNumber);
9597
}
96-
98+
9799
[Fact]
98100
public void TestDeserializingApplePayPayment()
99101
{
100102
ServiceMockHelper.MockJsonResponse("Fixtures/ApplePay/Paid.json");
101-
103+
102104
var payment = Payment.Fetch("a4a144ba-adc3-43bd-98e8-c80f2925fdc4");
103105
Assert.Equal(1000, payment.Amount);
104106
Assert.Equal("SAR", payment.Currency);
105107
Assert.Equal("Test Payment", payment.Description);
106108
Assert.Null(payment.CallbackUrl);
107-
109+
108110
Assert.IsType<ApplePayMethod>(payment.Source);
109111
var applePaySource = (ApplePayMethod) payment.Source;
110-
112+
111113
Assert.Equal("applepay", applePaySource.Type);
112114
Assert.Equal("XXXX-XXXX-XXXX-1111", applePaySource.Number);
113115
Assert.Equal("APPROVED", applePaySource.Message);
116+
Assert.Equal("moyasar_ap_je1iUidxhrh74257S891wvW", applePaySource.GatewayId);
117+
Assert.Equal("125478454231", applePaySource.ReferenceNumber);
114118
}
115-
119+
116120
[Fact]
117121
public void TestDeserializingStcPayPayment()
118122
{
119123
ServiceMockHelper.MockJsonResponse("Fixtures/StcPay/Paid.json");
120-
124+
121125
var payment = Payment.Fetch("50559d3b-e67f-4b3a-8df8-509dde19fe38");
122126
Assert.Equal(1000, payment.Amount);
123127
Assert.Equal("SAR", payment.Currency);
124128
Assert.Equal("Test Payment", payment.Description);
125129
Assert.Null(payment.CallbackUrl);
126-
130+
127131
Assert.IsType<StcPayMethod>(payment.Source);
128132
var method = (StcPayMethod) payment.Source;
129133
Assert.Equal("stcpay", method.Type);
@@ -135,30 +139,30 @@ public void TestDeserializingStcPayPayment()
135139
public void TestRefundPayment()
136140
{
137141
ServiceMockHelper.MockJsonResponse("Fixtures/CreditCard/Paid.json");
138-
142+
139143
var payment = Payment.Fetch("b6c01c90-a091-45a4-9358-71668ecbf7ea");
140144
var id = payment.Id;
141145
var amount = payment.Amount;
142-
146+
143147
ServiceMockHelper.MockJsonResponse("Fixtures/CreditCard/Refunded.json");
144148

145149
payment.Refund();
146-
150+
147151
Assert.Equal(id, payment.Id);
148152
Assert.Equal("refunded", payment.Status);
149153
Assert.Equal(amount, payment.RefundedAmount);
150154
Assert.Equal(DateTime.Parse("2019-01-03T10:14:14.414Z").ToUniversalTime(), payment.RefundedAt);
151155
}
152-
156+
153157
[Fact]
154158
public async void RefundHigherAmountMustThrowException()
155159
{
156160
ServiceMockHelper.MockJsonResponse("Fixtures/CreditCard/Paid.json");
157-
161+
158162
var payment = Payment.Fetch("b6c01c90-a091-45a4-9358-71668ecbf7ea");
159163
var id = payment.Id;
160164
var amount = payment.Amount;
161-
165+
162166
ServiceMockHelper.MockJsonResponse("Fixtures/CreditCard/Refunded.json");
163167

164168
await Assert.ThrowsAsync<ValidationException>
@@ -176,14 +180,14 @@ public void TestPaymentListing()
176180
Assert.IsType<CreditCard>(pagination.Items[0].Source);
177181
Assert.IsType<ApplePayMethod>(pagination.Items[1].Source);
178182
Assert.IsType<StcPayMethod>(pagination.Items[2].Source);
179-
183+
180184
Assert.Equal(2, pagination.CurrentPage);
181185
Assert.Equal(3, pagination.NextPage);
182186
Assert.Equal(1, pagination.PreviousPage);
183187
Assert.Equal(3, pagination.TotalPages);
184188
Assert.Equal(9, pagination.TotalCount);
185189
}
186-
190+
187191
internal static PaymentInfo GetValidPaymentInfo(IPaymentSource source = null)
188192
{
189193
return new PaymentInfo
@@ -212,7 +216,7 @@ private static CreditCardSource GetValidCcSource()
212216
Year = 2021,
213217
};
214218
}
215-
219+
216220
private static ApplePaySource GetValidApplePaySource()
217221
{
218222
return new ApplePaySource

0 commit comments

Comments
 (0)