Skip to content

Commit 0b7fa15

Browse files
authored
Merge pull request #205 from CyberSource/feature/handling-links-field-in-api
Feature/handling links field in api
2 parents 60361e5 + da11e79 commit 0b7fa15

File tree

7 files changed

+174
-94
lines changed

7 files changed

+174
-94
lines changed

Client/ApiClient.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,19 @@ public object Deserialize(RestResponse response, Type type) // CHANGED
706706
// at this point, it must be a model (json)
707707
try
708708
{
709-
return JsonConvert.DeserializeObject(response.Content, type, serializerSettings);
709+
if (type == typeof(Model.PblPaymentLinksAllGet200Response))
710+
{
711+
JsonSerializerSettings customSerializerSettings = new JsonSerializerSettings
712+
{
713+
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
714+
ContractResolver = new Utilities.CustomContractResolver()
715+
};
716+
return JsonConvert.DeserializeObject(response.Content, type, customSerializerSettings);
717+
}
718+
else
719+
{
720+
return JsonConvert.DeserializeObject(response.Content, type, serializerSettings);
721+
}
710722
}
711723
catch (Exception e)
712724
{

Model/PblPaymentLinksAllGet200Response.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,4 @@ public override int GetHashCode()
175175
}
176176

177177
}
178+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Newtonsoft.Json.Serialization;
2+
3+
namespace CyberSource.Utilities
4+
{
5+
public class CustomContractResolver : DefaultContractResolver
6+
{
7+
protected override string ResolvePropertyName(string propertyName)
8+
{
9+
if (propertyName == "Links")
10+
{
11+
return "_links";
12+
}
13+
/*if (propertyName == "SdkLinks")
14+
{
15+
return "links";
16+
}*/
17+
return base.ResolvePropertyName(propertyName);
18+
}
19+
20+
}
21+
}

generator/cybersource-csharp-template/ApiClient.mustache

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,19 @@ namespace {{packageName}}.Client
760760
// at this point, it must be a model (json)
761761
try
762762
{
763-
return JsonConvert.DeserializeObject(response.Content, type, serializerSettings);
763+
if (type == typeof(Model.PblPaymentLinksAllGet200Response))
764+
{
765+
JsonSerializerSettings customSerializerSettings = new JsonSerializerSettings
766+
{
767+
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
768+
ContractResolver = new Utilities.CustomContractResolver()
769+
};
770+
return JsonConvert.DeserializeObject(response.Content, type, customSerializerSettings);
771+
}
772+
else
773+
{
774+
return JsonConvert.DeserializeObject(response.Content, type, serializerSettings);
775+
}
764776
}
765777
catch (Exception e)
766778
{

generator/cybersource_dotnet_sdk_gen.bat

Lines changed: 28 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -6,106 +6,39 @@ rd /s /q ..\Model
66
rd /s /q ..\docs
77
rd /s /q ..\test
88

9-
java -jar swagger-codegen-cli-2.4.38.jar generate -t cybersource-csharp-template -i cybersource-rest-spec-dotnet.json -l csharp -o ../ -c cybersource-csharp-config.json
10-
11-
powershell -Command "Get-ChildItem '..\src\Cybersource\Api\*.cs' -Recurse | ForEach-Object { (Get-Content $_).Replace('Method.POST','Method.Post').Replace('Method.GET','Method.Get').Replace('Method.PATCH','Method.Patch').Replace('Method.DELETE','Method.Delete').Replace('Method.PUT','Method.Put') | Set-Content $_ }"
12-
13-
powershell -Command "(Get-Content ..\src\CyberSource\Api\SecureFileShareApi.cs) | ForEach-Object { $_ -replace 'null\); \/\/ Return statement', 'localVarResponse.Content); // Return statement' } | Set-Content ..\src\CyberSource\Api\SecureFileShareApi.cs"
14-
15-
powershell -Command "(Get-Content ..\src\CyberSource\Api\ReportDownloadsApi.cs) | ForEach-Object { $_ -replace 'null\); \/\/ Return statement', 'localVarResponse.Content); // Return statement' } | Set-Content ..\src\CyberSource\Api\ReportDownloadsApi.cs"
16-
17-
powershell -Command "(Get-Content ..\src\CyberSource\Api\TransactionBatchesApi.cs) | ForEach-Object { $_ -replace 'null\); \/\/ Return statement', 'localVarResponse.Content); // Return statement' } | Set-Content ..\src\CyberSource\Api\TransactionBatchesApi.cs"
18-
19-
REM Need to shorten filenames
20-
21-
powershell Rename-Item ..\src\Cybersource\Model\Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedInstrumentIdentifierProcessingInformationAuthorizationOptionsInitiatorMerchantInitiatedTransaction.cs Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedMerchantInitiatedTransaction.cs
22-
23-
powershell Rename-Item ..\src\Cybersource.Test\Model\Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedInstrumentIdentifierProcessingInformationAuthorizationOptionsInitiatorMerchantInitiatedTransactionTests.cs Tmsv2customersEmbeddedMerchantInitiatedTransactionTests.cs
24-
25-
powershell Rename-Item ..\docs\Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedInstrumentIdentifierProcessingInformationAuthorizationOptionsInitiatorMerchantInitiatedTransaction.md Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedMerchantInitiatedTransaction.md
26-
27-
powershell Rename-Item ..\src\Cybersource.Test\Model\Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedInstrumentIdentifierProcessingInformationAuthorizationOptionsInitiatorTests.cs Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedAuthorizationOptionsInitiatorTests.cs
28-
29-
powershell Rename-Item ..\src\Cybersource.Test\Model\Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedInstrumentIdentifierProcessingInformationAuthorizationOptionsTests.cs Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedAuthorizationOptionsTests.cs
30-
31-
powershell Rename-Item ..\src\Cybersource\Model\Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedInstrumentIdentifierProcessingInformationAuthorizationOptions.cs Tmsv2customersEmbeddedAuthorizationOptions.cs
32-
33-
powershell Rename-Item ..\src\Cybersource.Test\Model\RiskV1AddressVerificationsPost201ResponseAddressVerificationInformationStandardAddressAddress1Tests.cs RiskV1AddressVerificationsPost201ResponseStandardAddressAddress1Tests.cs
34-
35-
powershell Rename-Item ..\src\Cybersource\Model\Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedInstrumentIdentifierProcessingInformationAuthorizationOptionsInitiator.cs Tmsv2customersEmbeddedAuthorizationOptionsInitiator.cs
36-
37-
powershell Rename-Item ..\docs\Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedInstrumentIdentifierProcessingInformationAuthorizationOptionsInitiator.md Tmsv2customersEmbeddedAuthorizationOptionsInitiator.md
38-
39-
powershell Rename-Item ..\src\Cybersource.Test\Model\Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedInstrumentIdentifierLinksPaymentInstrumentsTests.cs Tmsv2customersEmbeddedPaymentInstrumentsTests.cs
40-
41-
powershell Rename-Item ..\src\Cybersource.Test\Model\Tmsv2customersEmbeddedDefaultPaymentInstrumentEmbeddedInstrumentIdentifierProcessingInformationTests.cs Tmsv2customersEmbeddedDefaultProcessingInformationTests.cs
42-
43-
44-
@REM renaming
45-
powershell Rename-Item ..\src\Cybersource.Test\Model\PaymentProductsCardProcessingConfigurationInformationConfigurationsCommonMerchantDescriptorInformationTests.cs PaymentProductsCardProcessingMerchantDescriptorInformationTests.cs
46-
47-
powershell Rename-Item ..\src\Cybersource.Test\Model\PaymentProductsCardProcessingConfigurationInformationConfigurationsFeaturesCardNotPresentPayoutsCurrenciesTests.cs PaymentProductsCardProcessingPayoutsCurrenciesTests.cs
48-
49-
powershell Rename-Item ..\src\Cybersource.Test\Model\PaymentProductsECheckConfigurationInformationConfigurationsFeaturesAccountValidationServiceInternalOnlyTests.cs PaymentProductsECheckServiceInternalOnlyTests.cs
50-
51-
powershell Rename-Item ..\src\Cybersource.Test\Model\PaymentProductsECheckConfigurationInformationConfigurationsFeaturesAccountValidationServiceProcessorsTests.cs PaymentProductsECheckProcessorsTests.cs
52-
53-
powershell Rename-Item ..\src\Cybersource.Test\Model\PaymentProductsPayerAuthenticationConfigurationInformationConfigurationsCardTypesVerifiedByVisaCurrenciesTests.cs PaymentProductsPayerAuthVerifiedByVisaCurrenciesTests.cs
54-
55-
powershell Rename-Item ..\src\Cybersource.Test\Model\PaymentProductsSecureAcceptanceConfigurationInformationConfigurationsNotificationsCustomerNotificationsTests.cs PaymentProductsSecureAcceptanceCustomerNotificationsTests.cs
56-
57-
powershell Rename-Item ..\src\Cybersource.Test\Model\PaymentProductsSecureAcceptanceConfigurationInformationConfigurationsNotificationsMerchantNotificationsTests.cs PaymentProductsSecureAcceptanceMerchantNotificationsTests.cs
58-
59-
powershell Rename-Item ..\src\Cybersource.Test\Model\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentGlobalPaymentInformationBasicInformationTests.cs PaymentProductsVirtualTerminalPaymentInformationBasicInformationTests.cs
9+
setlocal enabledelayedexpansion
10+
python replaceFieldNamesForPaths.py -i cybersource-rest-spec.json -o cybersource-rest-spec-dotnet.json > replaceFieldLogs.log
11+
del replaceFieldLogs.log
12+
endlocal
6013

61-
powershell Rename-Item ..\src\Cybersource.Test\Model\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentGlobalPaymentInformationMerchantDefinedDataFieldsTests.cs PaymentProductsVirtualTerminalMerchantDefinedDataFieldsTests.cs
62-
63-
powershell Rename-Item ..\src\Cybersource.Test\Model\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentGlobalPaymentInformationPaymentInformationTests.cs PaymentProductsVirtualTerminalPaymentInformationTests.cs
64-
65-
powershell Rename-Item ..\src\Cybersource.Test\Model\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentGlobalPaymentInformationTests.cs PaymentProductsVirtualTerminalCardNotPresentGlobalPaymentInformationTests.cs
66-
67-
powershell Rename-Item ..\src\Cybersource.Test\Model\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentReceiptInformationEmailReceiptTests.cs PaymentProductsVirtualTerminalReceiptInformationEmailReceiptTests.cs
68-
69-
powershell Rename-Item ..\src\Cybersource.Test\Model\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentReceiptInformationHeaderTests.cs PaymentProductsVirtualTerminalReceiptInformationHeaderTests.cs
70-
71-
powershell Rename-Item ..\src\Cybersource.Test\Model\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentReceiptInformationOrderInformationTests.cs PaymentProductsVirtualTerminalReceiptInformationOrderInformationTests.cs
72-
73-
powershell Rename-Item ..\src\Cybersource.Test\Model\RiskProductsDecisionManagerConfigurationInformationConfigurationsThirdpartyProviderAccurintCredentialsTests.cs RiskProductsDecisionManagerThirdpartyAccurintCredentialsTests.cs
74-
75-
powershell Rename-Item ..\src\Cybersource.Test\Model\RiskProductsDecisionManagerConfigurationInformationConfigurationsThirdpartyProviderCredilinkCredentialsTests.cs RiskProductsDecisionManagerThirdpartyCredilinkCredentialsTests.cs
76-
77-
powershell Rename-Item ..\src\Cybersource.Test\Model\RiskProductsDecisionManagerConfigurationInformationConfigurationsThirdpartyProviderSignifydCredentialsTests.cs RiskProductsDecisionManagerThirdpartySignifydCredentialsTests.cs
78-
79-
powershell Rename-Item ..\src\Cybersource\Model\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentGlobalPaymentInformationBasicInformation.cs PaymentProductsVirtualTerminalPaymentInformationBasicInformation.cs
80-
81-
powershell Rename-Item ..\src\Cybersource\Model\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentGlobalPaymentInformationMerchantDefinedDataFields.cs PaymentProductsVirtualTerminalMerchantDefinedDataFields.cs
82-
83-
powershell Rename-Item ..\src\Cybersource\Model\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentGlobalPaymentInformationPaymentInformation.cs PaymentProductsVirtualTerminalPaymentInformation.cs
84-
85-
powershell Rename-Item ..\src\Cybersource\Model\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentReceiptInformationEmailReceipt.cs PaymentProductsVirtualTerminalReceiptInformationEmailReceipt.cs
14+
java -jar swagger-codegen-cli-2.4.38.jar generate -t cybersource-csharp-template -i cybersource-rest-spec-dotnet.json -l csharp -o ../ -c cybersource-csharp-config.json
8615

87-
powershell Rename-Item ..\src\Cybersource\Model\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentReceiptInformationOrderInformation.cs PaymentProductsVirtualTerminalReceiptInformationOrderInformation.cs
16+
xcopy ..\src\cybersource ..\ /s /e /y /exclude:excludelist.txt
17+
md ..\test
18+
xcopy ..\src\cybersource.test ..\test /s /e /y
19+
rd /s /q ..\src
8820

89-
powershell Rename-Item ..\docs\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentGlobalPaymentInformationBasicInformation.md PaymentProductsVirtualTerminalPaymentInformationBasicInformation.md
21+
echo "starting of powershell commands"
9022

91-
powershell Rename-Item ..\docs\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentGlobalPaymentInformationMerchantDefinedDataFields.md PaymentProductsVirtualTerminalMerchantDefinedDataFields.md
23+
powershell -Command "Get-ChildItem '..\Api\*.cs' -Recurse | ForEach-Object { (Get-Content $_).Replace('Method.POST','Method.Post').Replace('Method.GET','Method.Get').Replace('Method.PATCH','Method.Patch').Replace('Method.DELETE','Method.Delete').Replace('Method.PUT','Method.Put') | Set-Content $_ }"
9224

93-
powershell Rename-Item ..\docs\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentGlobalPaymentInformationPaymentInformation.md PaymentProductsVirtualTerminalPaymentInformation.md
25+
powershell -Command "(Get-Content ..\Api\SecureFileShareApi.cs) | ForEach-Object { $_ -replace 'null\); \/\/ Return statement', 'localVarResponse.Content); // Return statement' } | Set-Content ..\Api\SecureFileShareApi.cs"
9426

95-
powershell Rename-Item ..\docs\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentReceiptInformationEmailReceipt.md PaymentProductsVirtualTerminalReceiptInformationEmailReceipt.md
27+
powershell -Command "(Get-Content ..\Api\ReportDownloadsApi.cs) | ForEach-Object { $_ -replace 'null\); \/\/ Return statement', 'localVarResponse.Content); // Return statement' } | Set-Content ..\Api\ReportDownloadsApi.cs"
9628

97-
powershell Rename-Item ..\docs\PaymentProductsVirtualTerminalConfigurationInformationConfigurationsCardNotPresentReceiptInformationOrderInformation.md PaymentProductsVirtualTerminalReceiptInformationOrderInformation.md
29+
powershell -Command "(Get-Content ..\Api\TransactionBatchesApi.cs) | ForEach-Object { $_ -replace 'null\); \/\/ Return statement', 'localVarResponse.Content); // Return statement' } | Set-Content ..\Api\TransactionBatchesApi.cs"
9830

99-
powershell -Command " Set-Content ..\src\CyberSource\Api\SecureFileShareApi.cs ((get-content ..\src\CyberSource\Api\SecureFileShareApi.cs -raw) -replace '\*_\/_\*;charset=utf-8', '*/*;charset=utf-8') "
31+
powershell -Command " Set-Content ..\Api\SecureFileShareApi.cs ((get-content ..\Api\SecureFileShareApi.cs -raw) -replace '\*_\/_\*;charset=utf-8', '*/*;charset=utf-8') "
10032

10133
REM For changing nuspec filename in csproj file
102-
powershell -Command "(Get-Content ..\src\CyberSource\CyberSource.csproj) | ForEach-Object { $_ -replace '<None Include=\"CyberSource.nuspec\" />', '<None Include=\"cybersource-rest-client-dotnet.nuspec\" />' } | Set-Content ..\src\CyberSource\CyberSource.csproj"
34+
powershell -Command "(Get-Content ..\CyberSource.csproj) | ForEach-Object { $_ -replace '<None Include=\"CyberSource.nuspec\" />', '<None Include=\"cybersource-rest-client-dotnet.nuspec\" />' } | Set-Content ..\CyberSource.csproj"
10335

104-
powershell -Command "(Get-Content ..\src\CyberSource.Test\CyberSource.Test.csproj) | ForEach-Object { $_ -replace 'CyberSource\\CyberSource.csproj', 'cybersource-rest-client-dotnet.csproj' } | ForEach-Object { $_ -replace '<Name>CyberSource</Name>', '<Name>cybersource-rest-client-dotnet</Name>' } | Set-Content ..\src\CyberSource.Test\CyberSource.Test.csproj"
36+
powershell -Command "(Get-Content ..\test\CyberSource.Test.csproj) | ForEach-Object { $_ -replace 'CyberSource\\CyberSource.csproj', 'cybersource-rest-client-dotnet.csproj' } | ForEach-Object { $_ -replace '<Name>CyberSource</Name>', '<Name>cybersource-rest-client-dotnet</Name>' } | Set-Content ..\test\CyberSource.Test.csproj"
10537

10638
REM For Renaming the .csproj file Name from Cybersource to cybersource-rest-client-dotnet
107-
powershell Rename-Item ..\src\CyberSource\CyberSource.csproj cybersource-rest-client-dotnet.csproj
108-
powershell Rename-Item ..\src\CyberSource.Test\CyberSource.Test.csproj cybersource-rest-client-dotnet.Test.csproj
39+
del ..\cybersource-rest-client-dotnet.csproj
40+
powershell Rename-Item ..\CyberSource.csproj cybersource-rest-client-dotnet.csproj
41+
powershell Rename-Item ..\test\CyberSource.Test.csproj cybersource-rest-client-dotnet.Test.csproj
10942

11043
REM For changing project filenames in sln file
11144
powershell -Command "(Get-Content ..\CyberSource.sln) | ForEach-Object { $_ -replace 'CyberSource', 'cybersource-rest-client-dotnet' } | Set-Content ..\CyberSource.sln"
@@ -115,16 +48,19 @@ del ..\cybersource-rest-client-dotnet.sln
11548

11649
powershell Rename-Item ..\CyberSource.sln cybersource-rest-client-dotnet.sln
11750

118-
xcopy ..\src\cybersource ..\ /s /e /y /exclude:excludelist.txt
51+
echo "completed powershell commands"
52+
53+
@REM replace sdkLinks fieldName to links for supporting links field name in request/response body
54+
echo "starting of replacing the links keyword in PblPaymentLinksAllGet200Response.cs model"
55+
powershell -Command "Set-Content ..\Model\PblPaymentLinksAllGet200Response.cs ((Get-Content ..\Model\PblPaymentLinksAllGet200Response.cs -Raw) -replace '\[DataMember\(Name=\"sdkLinks\", EmitDefaultValue=false\)\]', '[DataMember(Name=\"links\", EmitDefaultValue=false)]')"
56+
echo "completed the task of replacing the links keyword in PblPaymentLinksAllGet200Response.cs model"
57+
11958
git checkout ..\README.md
12059
git checkout ..\Api\OAuthApi.cs
12160
git checkout ..\Model\AccessTokenResponse.cs
12261
git checkout ..\Model\CreateAccessTokenRequest.cs
123-
md ..\test
124-
xcopy ..\src\cybersource.test ..\test /s /e /y
125-
git checkout ..\test\packages.config
12662

127-
rd /s /q ..\src
63+
git checkout ..\test\packages.config
12864

12965
del ..\Client\IReadableConfiguration.cs
13066

0 commit comments

Comments
 (0)