COGWare.PeachRefunds 1.0.6

There is a newer version of this package available.
See the version list below for details.
dotnet add package COGWare.PeachRefunds --version 1.0.6                
NuGet\Install-Package COGWare.PeachRefunds -Version 1.0.6                
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.PeachRefunds" Version="1.0.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add COGWare.PeachRefunds --version 1.0.6                
#r "nuget: COGWare.PeachRefunds, 1.0.6"                
#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.PeachRefunds as a Cake Addin
#addin nuget:?package=COGWare.PeachRefunds&version=1.0.6

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

Peach Payments Transaction Refunds

Process refunds for transactions submitted via the Peach Payments payment gateway

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.PeachRefunds -Version <version>
Install-Package Microsoft.Extensions.Logging.Abstractions CLI:
dotnet add package --version <version> COGWare.PeachRefunds dotnet add package Microsoft.Extensions.Logging.Abstractions

Add Config

Add the PeachRefunds.IsProduction key to your settings file, eg:
<add key="PeachRefunds.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 PeachPayments.RefundHelper.ProcessRefund(
            // An instance of the RefundConfig object containing details of the
            // Peach Payments entity that the original transaction was processed against.
            // These details are available in the Peach Payments Console. 
            new RefundConfig() {
                // Your merchant entityId.
                EntityId = "xyz123",
                // Your merchant secret.
                Secret = "123xyz"
            },
            // An instance of a Refund object representing the refund to be processed.
            new Refund() {
                // The amount to be refunded.
                Amount = 1.00,
                // Currency code.
                Currency = "ZAR",
                // Your refund identifier.
                Id = "1",
                // The original (Peach Payments) transactionId of the payment.
                TransactionId = "456xyz"
            },
            // optional logger
            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! " +
                "Refund reference: '" + refundResult.Id + "'");
        } else {
            // Update the status of the refund in your refund system, optionally including the
            // return code and description for analysis and manual resolution (if necessary).
            Console.WriteLine("Refund failed: " +
                refundResult.Result!.Code + ", " +
                refundResult.Result!.Description);
        }
    } 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 PeachPayments.RefundHelper.ProcessRefund(
            // An instance of the RefundConfig object containing details of the
            // Peach Payments entity that the original transaction was processed against.
            // These details are available in the Peach Payments Console. 
            new RefundConfig() {
                // Your merchant entityId.
                EntityId = "xyz123",
                // Your merchant secret.
                Secret = "123xyz"
            },
            // An instance of a Refund object representing the refund to be processed.
            new Refund() {
                // The amount to be refunded.
                Amount = 1.00,
                // Currency code.
                Currency = "ZAR",
                // Your refund identifier.
                Id = "1",
                // The original (Peach Payments) transactionId of the payment.
                TransactionId = "456xyz"
            });

        // 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! " +
                "Refund reference: '" + refundResult.Id + "'");
        } else {
            // Update the status of the refund in your refund system, optionally including the
            // return code and description for analysis and manual resolution (if necessary).
            Console.WriteLine("Refund failed: " +
                refundResult.Result!.Code + ", " +
                refundResult.Result!.Description);
        }
    } catch(Exception ex) {
        Console.WriteLine("ERROR: " + ex.GetBaseException().Message);
    }

Response object:

RefundResult

An object representing the response from the Peach Payments API.

  • Id:(String) - The Peach Payments transaction identifier for this specific refund.
  • ReferenceId: (String) - The original payment transaction identifier.
  • PaymentType: (String) - This will be "RF", denoting a refund.
  • Amount: (String) - The amount that was refunded.
  • Currency: (String) - The currency that the refund was processed in.
  • Descriptor: (String) - The merchant payment description.
  • MerchantTransactionId (String) - The original merchant transaction id.
  • Result (Object) - An object containing the refund response result.
    • Code (String) - The Peach Payments response code.
    • Description (String) - Description associated with the response code.
  • ResultDetail (Object) - An object containing the technical details of the refund
    • ConnectorTxID1 (String) - Downstream (credit card issuer) connection transaction identifier.
    • ConnectorTxID2 (String) - Additional downstream (credit card issuer) connection transaction identifier.
    • AuthorisationCode (String) - Downstream (credit card issuer) authorization code.
    • AcquirerReference (String) - Downstream (credit card issuer) reference.
    • AcquirerResponse (String) - Downstream (credit card issuer) response.
  • BuildNumber (String) - Peach Payments refund module build number.
  • Timestamp (DateTime) - When this refund was processed.
  • NDC (String) - No idea, will find out.
  • 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

Feedback

I welcome comments, suggestions, feature requests and even honest criticism 😃

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
2.0.1 213 6/10/2023
2.0.0 166 6/10/2023
1.0.7 184 5/27/2023
1.0.6 177 5/27/2023
1.0.5 181 5/19/2023
1.0.4 189 5/10/2023
1.0.3 166 5/5/2023
1.0.2 168 5/5/2023
1.0.1 173 5/4/2023
1.0.0 166 5/4/2023

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