Skip to content

Feature/add batch sample code #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Source/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ public Dictionary<string, string> GetIntermediateConfiguration()
// _configurationDictionary.Add("proxyUsername", string.Empty);
// _configurationDictionary.Add("proxyPassword", string.Empty);
return _configurationDictionary;
}

public Dictionary<string, string> GetMerchantDetailsForBatchUploadSample()
{
_configurationDictionary.Add("authenticationType", "JWT");
_configurationDictionary.Add("merchantID", "qaebc2");
_configurationDictionary.Add("runEnvironment", "apitest.cybersource.com");

_configurationDictionary.Add("keyAlias", "qaebc2");
_configurationDictionary.Add("keyPass", "?Test1234");
_configurationDictionary.Add("keysDirectory", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\..\\Source\\Resource"));
_configurationDictionary.Add("keyFilename", "qaebc2");
return _configurationDictionary;
}


}
}
5 changes: 5 additions & 0 deletions Source/Resource/batchapiTest.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
merchantID=qaebc2,batchID=rgdltnd0,recordCount=2,[email protected],targetAPIVersion=1.86,creationDate=2025-03-05,reference=
merchantID,merchantReferenceCode,merchantDefinedData_field1,ccAuthService_run,billTo_firstName,billTo_lastName,billTo_email,billTo_street1,billTo_city,billTo_state,billTo_country,billTo_postalCode,card_accountNumber,card_expirationMonth,card_expirationYear,card_cardType,purchaseTotals_currency,purchaseTotals_grandTotalAmount,item_#_productCode
qaebc2,1,4837,true,Jay,Smith,[email protected],8 Mission Street,San Francisco,CA,US,94101,4111111111111111,12,2036,001,GBP,8.00,1
qaebc2,2,7209,true,Jay,Smith,[email protected],8 Mission Street,San Francisco,CA,US,94101,4111111111111111,12,2036,001,GBP,8.00,1
END,SUM=16.00
Binary file added Source/Resource/qaebc2.p12
Binary file not shown.
55 changes: 55 additions & 0 deletions Source/Samples/TransactionBatches/UploadTransactionBatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using CyberSource.Api;
using CyberSource.Client;
using CyberSource.Model;
using Cybersource_rest_samples_dotnet;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Text;

namespace Cybersource_rest_samples_dotnet.Samples.TransactionBatches
{
public class UploadTransactionBatch
{
public static void WriteLogAudit(int status)
{
var filePath = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString().Split('.');
var filename = filePath[filePath.Length - 1];
Console.WriteLine($"[Sample Code Testing] [{filename}] {status}");
}

public static void Run()
{
// Get the file path from the resources folder
String filename = "batchapiTest.csv";

Stream file = null;
try
{
string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\..\\Source\\Resource", filename);
file = new FileStream(filePath, FileMode.Open, FileAccess.Read);
}
catch (FileNotFoundException)
{
Console.WriteLine("File Not Found : Kindly verify the path.");
}

try
{
var configDictionary = new Cybersource_rest_samples_dotnet.Configuration().GetMerchantDetailsForBatchUploadSample();
var clientConfig = new CyberSource.Client.Configuration(merchConfigDictObj: configDictionary);
var apiInstance = new TransactionBatchesApi(clientConfig);
ApiResponse<object> result = apiInstance.UploadTransactionBatchWithHttpInfo(file);
Console.WriteLine(result);
WriteLogAudit(result.StatusCode);
}
catch (ApiException e)
{
Console.WriteLine("Exception on calling the API : " + e.Message);
WriteLogAudit(e.ErrorCode);
}
}

}
}
3 changes: 3 additions & 0 deletions cybersource-rest-samples-csharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@
<Compile Include="Source\Samples\TransactionBatches\GetIndividualBatchFile.cs" />
<Compile Include="Source\Samples\TransactionBatches\GetListOfBatchFiles.cs" />
<Compile Include="Source\Samples\TransactionBatches\GetTransactionDetailsForGivenBatchId.cs" />
<Compile Include="Source\Samples\TransactionBatches\UploadTransactionBatch.cs" />
<Compile Include="Source\Samples\TransactionDetails\RetrieveTransaction.cs" />
<Compile Include="Source\Samples\TransactionSearch\CreateSearchRequest.cs" />
<Compile Include="Source\Samples\TransactionSearch\GetSearchResults.cs" />
Expand Down Expand Up @@ -446,6 +447,8 @@
<None Include="Source\Resource\testrest.p12" />
<None Include="Source\Resource\testrest_cpctv.p12" />
<None Include="Source\Resource\TRRReport.json" />
<None Include="Source\Resource\batchapiTest.csv" />
<None Include="Source\Resource\qaebc2.p12" />
</ItemGroup>
<ItemGroup>
<Content Include="Source\lib\net461\ApiSdk.dll" />
Expand Down