COGWare.CyberSourceRefunds 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package COGWare.CyberSourceRefunds --version 1.0.1                
NuGet\Install-Package COGWare.CyberSourceRefunds -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="COGWare.CyberSourceRefunds" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add COGWare.CyberSourceRefunds --version 1.0.1                
#r "nuget: COGWare.CyberSourceRefunds, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install COGWare.CyberSourceRefunds as a Cake Addin
#addin nuget:?package=COGWare.CyberSourceRefunds&version=1.0.1

// Install COGWare.CyberSourceRefunds as a Cake Tool
#tool nuget:?package=COGWare.CyberSourceRefunds&version=1.0.1                

CyberSource Credit Card Refunds

Process refunds for transactions submitted via the CyberSource payment platform

Getting Started

Install this NuGet package and the Microsoft.Extensions.Logging.Abstractions package into your .NET Core 6 or .NET Framework 4.8 application.

Package Manager:
Install-Package COGWare.CyberSourceRefunds -Version <version>
Install-Package Microsoft.Extensions.Logging.Abstractions

CLI:
dotnet add package --version <version> COGWare.CyberSourceRefunds
dotnet add package Microsoft.Extensions.Logging.Abstractions

Add Config

Add the CyberSourceRefunds.IsProduction key to your settings file, eg:
<add key="CyberSourceRefunds.IsProduction" value="false" />

Usage

With logging:

    // Create your logger from the logging framework's extensions package (in this case, NLog)
    var logger = LoggerFactory.Create(builder => builder.AddNLog()).CreateLogger<Program>();

    logger.LogInformation("starting");

    try {
        RefundResult? refundResult = await CyberSourceRefunds.RefundHelper.ProcessRefund(
            // An instance of the RefundConfig object containing details of the
            // CyberSource entity that the original transaction was processed against.
            // These details are available in the CyberSource Merchant Console. 
            new RefundConfig() {                        
                // The merchant identifier.
                MID = "your_mid_here",
                // Your merchant API key.
                MerchantKey = "you_merchant_key_here",
                // Your merchant API secret.
                MerchantSecret = "your_merchant_secret_here"
            },
            // An instance of a Refund object representing the refund to be processed.
            new Refund() {
                // The amount to be refunded.
                Amount = 1,
                // Your refund identifier (must be unique).
                Id = "your_unique_identifier_here",
                // This will appear as the reference for the refund
                Comments = "your_comment_here",
                // The original (CyberSource) RequestId of the authorization
                RequestId = "CyberSource_requestId_here"
            },
            logger);

        // Checks the status of the refund against the API response codes to 
        // determine if the refund can be considered successful.
        if(refundResult!.IsSuccessful) {
            // Update the status of the refund in your refund system.
            Console.WriteLine("Refund processed successfully! " +
                "Your refund identifier: '" + refundResult.Id + "', " +
                "CyberSource refund reference: '" + refundResult.RefundId + "'");
        } else {
            // Update the status of the refund in your refund system, optionally including the
            // errors for analysis and manual resolution (if necessary).
            Console.WriteLine("Refund ('" + refundResult.Id + "') failed: " +
                refundResult?.Reason + " - " + 
                refundResult?.Message);
        }
    } catch(Exception ex) {
        Console.WriteLine("ERROR: " + ex.GetBaseException().Message);
    }

    logger.LogInformation("complete");

Without logging:

Note: Even though you have opted not log, your project will still require a reference to Microsoft.Extensions.Logging.Abstractions.

    try {
        RefundResult? refundResult = await CyberSourceRefunds.RefundHelper.ProcessRefund(
            // An instance of the RefundConfig object containing details of the
            // CyberSource entity that the original transaction was processed against.
            // These details are available in the CyberSource Merchant Console. 
            new RefundConfig() {                        
                // The merchant identifier.
                MID = "your_mid_here",
                // Your merchant API key.
                MerchantKey = "you_merchant_key_here",
                // Your merchant API secret.
                MerchantSecret = "your_merchant_secret_here"
            },
            // An instance of a Refund object representing the refund to be processed.
            new Refund() {
                // The amount to be refunded.
                Amount = 1,
                // Your refund identifier (must be unique).
                Id = "your_unique_identifier_here",
                // This will appear as the reference for the refund
                Comments = "your_comment_here",
                // The original (CyberSource) RequestId of the authorization
                RequestId = "CyberSource_requestId_here"
            });

        // Checks the status of the refund against the API response codes to 
        // determine if the refund can be considered successful.
        if(refundResult!.IsSuccessful) {
            // Update the status of the refund in your refund system.
            Console.WriteLine("Refund processed successfully! " +
                "Your refund identifier: '" + refundResult.Id + "', " +
                "CyberSource refund reference: '" + refundResult.RefundId + "'");
        } else {
            // Update the status of the refund in your refund system, optionally including the
            // errors for analysis and manual resolution (if necessary).
            Console.WriteLine("Refund ('" + refundResult.Id + "') failed: " +
                refundResult?.Reason + " - " + 
                refundResult?.Message);
        }
    } catch(Exception ex) {
        Console.WriteLine("ERROR: " + ex.GetBaseException().Message);
    }

Response object:

RefundResult

An object representing the response from the CyberSource API.

  • Id:(String) - Your refund identifier.
  • RefundId: (String) - The CyberSource transaction identifier for this specific refund.
  • ClientReferenceInformation (Object) - Information you can use to reference this refund request.
    • Code (String) - A code associated with this refund request.
    • TransactionId (String) - Your unique refund transaction identifier.
    • Comments (String) - The comment submitted along with this refund request.
  • ErrorInformation (Object) - May be populated with error details - depending on severity of error.
    • Reason (String) - Reason for the error.
    • Message (String) - Detail of the error.
  • ProcessorInformation (Object) - Upstream processing information.
    • ApprovalCode (String) - ?
    • NetworkTransactionId (String) - ?
    • RetrievalReferenceNumber (String) - ?
    • ResponseCode (String) - Not sure, but it seems '00' is good.
  • ReconciliationId: (String) - This seems to match the original RequestId.
  • Status: (String) - Usually "PENDING" since the refund is not immediately processed.
  • Reason: (String) - Usually provides the reason for the refund being rejected.
  • Message: (String) - A longer description for the associated reason.
  • Details: (List) - If there are specific fields that are invalid, this collection can contain details of those offending items.
    • Field (String) - The invalid/offencding field.
    • Reason (String) - The reason why CyberSource has taken offence to this field/value.
  • IsSuccessful (Boolean) - A flag indicating if the refund was successfully processed.

Logging:

Implements Microsoft.Extensions.Logging, so log away with any compatible logging framework,eg: NLog This package logs at DEBUG level.

Additional documentation

The CyberSource documentation can be a bit overwhelming to wade through. Warning: here be dragons!

Feedback

I welcome comments, suggestions, feature requests and even honest criticism 😃
Heck, just let me know if you found this useful at all.

Want to show your appreciation?

That's mighty generous - thank you!
Buy me a coffee

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 222 5/27/2023
1.0.1 157 5/27/2023
1.0.0 166 5/24/2023

Added exception handling for missing config, support for .NET 4.8, and some basic metrics to determine usage.