File tree 2 files changed +13
-15
lines changed
connect-examples/v2/csharp_payment/PaymentExample
2 files changed +13
-15
lines changed Original file line number Diff line number Diff line change 2
2
3
3
using Square . Connect . Api ;
4
4
using Square . Connect . Model ;
5
+ using Square . Connect . Client ;
5
6
6
7
namespace PaymentExample
7
8
{
@@ -38,24 +39,21 @@ public static string Charge(string nonce)
38
39
// Monetary amounts are specified in the smallest unit of the applicable currency.
39
40
// This amount is in cents. It's also hard-coded for $1.00,
40
41
// which isn't very useful.
41
- Money amount = NewMoney ( 100 , " USD" ) ;
42
+ Money amount = new Money ( 100 , Money . CurrencyEnum . USD ) ;
42
43
43
44
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
46
47
{
48
+ var response = _transactionApi . Charge ( _accessToken , _locationId , body ) ;
47
49
return "Transaction complete\n " + response . ToJson ( ) ;
48
- } else
50
+ }
51
+ catch ( ApiException e )
49
52
{
50
- return response . Errors . ToString ( ) ;
53
+ return e . Message ;
51
54
}
52
55
}
53
56
54
- public static Money NewMoney ( int amount , string currency )
55
- {
56
- return new Money ( amount , Money . ToCurrencyEnum ( currency ) ) ;
57
- }
58
-
59
57
public static string NewIdempotencyKey ( )
60
58
{
61
59
return Guid . NewGuid ( ) . ToString ( ) ;
Original file line number Diff line number Diff line change 1
1
<?xml version =" 1.0" encoding =" utf-8" ?>
2
2
<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" />
8
8
</packages >
You can’t perform that action at this time.
0 commit comments