SFPY.net 1.2.1

dotnet add package SFPY.net --version 1.2.1
NuGet\Install-Package SFPY.net -Version 1.2.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="SFPY.net" Version="1.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SFPY.net --version 1.2.1
#r "nuget: SFPY.net, 1.2.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 SFPY.net as a Cake Addin
#addin nuget:?package=SFPY.net&version=1.2.1

// Install SFPY.net as a Cake Tool
#tool nuget:?package=SFPY.net&version=1.2.1

SFPY.net

The official Safepay .NET library, supporting .NET Standard 2.0+, .NET Core 2.0+, and .NET Framework 4.6.1+.

Usage

Installation

Using the .NET Core command-line interface (CLI) tools:

dotnet add package SFPY.net

Imports

using Safepay;

Configuration

Configure your client with the following keys that may be obtained from the merchant dashboard.

// Your merchant API key
SafepayConfiguration.ApiKey = "sec_a7cc6fc1-088d-4f35-9dac-2bab2cb234a1";

// Your webhook secret
SafepayConfiguration.WebhookSecret = "a30200d73f7e8a6c7bed2ef2b925d575eb198cf31d1145d9e52c102081cb6065";

// The target environment. This is set to production by default.
SafepayConfiguration.Environment = "sandbox";

Creating a Safepay Checkout session

To create a Safepay Checkout session, you must create a Tracker and then generate a session URL. You should then redirect your customer to the Checkout URL.

Creating a tracker requires an amount and a currency.

Parameter Type Required
amount float Yes
currency PKR or USD Yes

You must specify the following when generating the Checkout session:

Parameter Type Description Required
token string The Tracker token Yes
orderId string Your internal invoice / order id Yes
cancelUrl string Url to redirect to if user cancels the flow Yes
redirectUrl string Url to redirect to if user completes the flow Yes
source string Optional, defaults to custom No
webhooks boolean Optional, defaults to false. Set to true for redirection No

An example is shown below:

// Initialize the HTTP client
SafepayClient.InitializeApiClient(false);

// Create a Tracker with the desired amount and currency
var response = await Order.CreateTracker(100.50, "PKR");
var data = response.Data;

// Generate the Checkout session URL
var checkout = Checkout.CreateSession(data.Token, "AX0000001", "https://google.com", "https://google.com", usingWebhookVerification:true);

Verifying a Safepay Webhook payload

You may subscribe to various events from Safepay from the Webhooks tab in the Developer section on the merchant dashboard. To verify the contents of the Webhook, you may refer to the following snippet.

// Create an example payload
var json = "{\"token\":\"CNK4P631F43C73AIIF7G\",\"client_id\":\"sec_c50daabe-49a4-4a62-8adf-25391c36e204\",\"type\":\"payment:created\",\"endpoint\":\"https://example.com\",\"notification\":{\"tracker\":\"track_69b331f2-5ef0-4dd5-bcb4-d288fbdac0ef\",\"reference\":\"969025\",\"intent\":\"CYBERSOURCE\",\"fee\":\"32.77\",\"net\":\"967.23\",\"user\":\"hzaidi@getsafepay.com\",\"state\":\"PAID\",\"amount\":\"1000.00\",\"currency\":\"PKR\",\"metadata\":{\"source\":\"checkout\"}},\"delivery_attempts\":1,\"resource\":\"notification\",\"next_attempt_at\":\"2024-03-06T10:59:36Z\",\"created_at\":\"2024-03-06T10:59:36Z\"}";

// Construct the request with the payload and the matching signature
var request = new HttpRequestMessage {
  RequestUri = new Uri("http://localhost/api/shoppingcart"),
  Content = new StringContent(json, Encoding.UTF8, "application/json")
};
request.Headers.Add("X-SFPY-SIGNATURE", "ed3b0a78fef22b658e0734a4d9072d148a2cc53c6ebade6323f9bfa6ea1658e5b603f8cea50de1f288707363663f42f50116d777ca634bca6f8ed1adfd462b1a");

// Verify that the Webhook was sent by Safepay
bool isValid = Verification.VerifyWebhook(request);

Support

New features and bug fixes are released on the latest major version of the Safepay .NET client library. If you are on an older major version, we recommend that you upgrade to the latest in order to use the new features and bug fixes including those for security vulnerabilities. Older major versions of the package will continue to be available for use, but will not be receiving any updates.

Development

For any requests, bug or comments, please open an issue or submit a pull request.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  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 is compatible.  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 Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.2.1 114 3/17/2024
1.2.0 103 3/13/2024
1.1.0 106 3/12/2024
1.0.0 88 3/8/2024