Skip to content

Commit 11c7a4e

Browse files
authored
Fix the CSharp exmaple adapting the latest SDK (square#25)
1 parent 6dd6012 commit 11c7a4e

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

connect-examples/v2/csharp_payment/PaymentExample/Default.aspx.cs

+8-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
using Square.Connect.Api;
44
using Square.Connect.Model;
5+
using Square.Connect.Client;
56

67
namespace PaymentExample
78
{
@@ -38,24 +39,21 @@ public static string Charge(string nonce)
3839
// Monetary amounts are specified in the smallest unit of the applicable currency.
3940
// This amount is in cents. It's also hard-coded for $1.00,
4041
// which isn't very useful.
41-
Money amount = NewMoney(100, "USD");
42+
Money amount = new Money(100, Money.CurrencyEnum.USD);
4243

4344
ChargeRequest body = new ChargeRequest(AmountMoney: amount, IdempotencyKey: uuid, CardNonce: nonce);
44-
var response = _transactionApi.Charge(_accessToken, _locationId, body);
45-
if (response.Errors == null)
45+
46+
try
4647
{
48+
var response = _transactionApi.Charge(_accessToken, _locationId, body);
4749
return "Transaction complete\n" + response.ToJson();
48-
} else
50+
}
51+
catch (ApiException e)
4952
{
50-
return response.Errors.ToString();
53+
return e.Message;
5154
}
5255
}
5356

54-
public static Money NewMoney(int amount, string currency)
55-
{
56-
return new Money(amount, Money.ToCurrencyEnum(currency));
57-
}
58-
5957
public static string NewIdempotencyKey()
6058
{
6159
return Guid.NewGuid().ToString();
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0" targetFramework="net45" />
4-
<package id="Microsoft.Net.Compilers" version="1.0.0" targetFramework="net45" developmentDependency="true" />
5-
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net45" />
6-
<package id="RestSharp" version="105.1.0" targetFramework="net45" />
7-
<package id="Square.Connect" version="0.1.0" targetFramework="net45" />
3+
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.4" targetFramework="net45" />
4+
<package id="Microsoft.Net.Compilers" version="2.1.0" targetFramework="net45" developmentDependency="true" />
5+
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net45" />
6+
<package id="RestSharp" version="105.2.3" targetFramework="net45" />
7+
<package id="Square.Connect" version="2.0.2.71" targetFramework="net45" />
88
</packages>

0 commit comments

Comments
 (0)