Code Monkey home page Code Monkey logo

swedbank-pay-sdk-dotnet's Introduction

Swedbank Pay SDK for .NET

Swedbank Pay SDK for .NET

Latest stable NuGet package Latest prerelease NuGet package NuGet downloads CLA assistant License Contributor Covenant

SwedbankPay.Sdk is a library that allows you to interact with Swedbank Pay's API Platform in a statically typed client targeting .NET Standard 2.0. For information about which runtimes (.NET Framework, .NET Core, Mono, Xamarin, etc.) support .NET Standard 2.0, see Microsoft's documentation.

About

UNSUPPORTED: This SDK is at an early stage of development and is not supported as of yet by Swedbank Pay. It is provided as a convenience to speed up your development, so please feel free to play around. However, if you need support, please wait for a future, stable release.

Supported APIs Version 3.1

  • Payment Order
    • Create PaymentOrder
    • GET PaymentOrder
    • UpdateOrder
    • Capture
    • Cancel
    • Reversal
    • Abort
  • Tokens
    • Network Tokenization
    • Get stored details
    • Delete stored details

Use Cases

  • Subscriptions
  • Verify
    • Collect and store payment details for future usage.
    • Collect and replace current payment details (Subscriptions)
  • Instrument Mode (Build your own menu)
  • Customise payment selection & favorite method

Sample App

Check the the samples folder. To run the sample site. Make sure to add your PayeeId and ApiBaseUrl from SwedbankPay in appsettings.json

You will also need to add the token from SwedbankPay in secrets.json by running the following command in the project root folder. dotnet user-secrets set "Token" "{Your token}" --project src/Samples/Sample.AspNetCore

Getting started

Install the SwedbankPay.Sdk NuGet in your project:

dotnet add package SwedbankPay.Sdk

To configure the SDK in one line using Microsoft.Extensions.DependencyInjection, you need to install SwedbankPay.Sdk.Extensions. The SDK can then be configured as such: (This requires that you have added SwedbankPay.Sdk.Extensions)

public void ConfigureServices(IServiceCollection services)
{
    services.AddSwedbankPayClient(ApiUrl, AuthenticationToken);
    ...
}

This will add the ISwedbankPayClient to the system, as well as interfaces for all api's in case you want to have more control over what is injected. See the samples for inspiration and usage. Using this to configure the SwedbankPay.Sdk will set up a LoggingDelegatingHandler that aids in logging error responses from the api.

Contributing

Bug reports and pull requests are welcome on GitHub. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct and sign the contributor's license agreement.

License

The code within this repository is available as open source under the terms of the Apache 2.0 License and the contributor's license agreement.

swedbank-pay-sdk-dotnet's People

Contributors

antonsehovac avatar asbjornu avatar clement-joye avatar dependabot-preview[bot] avatar dependabot[bot] avatar joakimmag avatar johnkors avatar karlfristedt76 avatar lounge avatar maool avatar mergify[bot] avatar nacorpio avatar nullableint avatar toreerstad avatar trieutran91 avatar zunkas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

swedbank-pay-sdk-dotnet's Issues

Improve API Problem handling

This issue is about how to identify Problems – which is neccessary for correct handling in client implementations (e.g. when a payment fails beacuase of insufficient funds etc).

I'm posting this as a new issue here, but it started off as a conversation in this pull request: #94

I think Swedbank have made a good choice by transitioning over to RFC7807 for error reporting. But the way you currently have implemented and documented it makes it hard for us to use on the client-side.
E.g. this JSON response:

{
  "transactionList": [
    {
      "failedReason": "ExternalResponseError",
      "failedActivityName": "Authorize",
      "failedErrorCode": "REJECTED_BY_ACQUIRER_CARD_STOLEN",
      "failedErrorDescription": "card stolen, response-code: 43",
      "isOperational": false,
      "problem": {
        "type": "https://api.payex.com/psp/errordetail/creditcard/acquirercardstolen",
        "title": "Operation failed",
        "status": 403,
        "detail": "Unable to complete Authorization transaction, look at problem node!",
        "problems": [
          {
            "name": "ExternalResponse",
            "description": "REJECTED_BY_ACQUIRER_CARD_STOLEN-card stolen, response-code: 43"
          }
        ]
      }
    }
  ]
}

The type URI https://api.payex.com/psp/errordetail/creditcard/acquirercardstolen do not dereference to an HTML explaining the problem.
I found this documentation though for some legacy error codes:
https://developer.swedbankpay.com/resources/test-data#amount-error-testing-method
But I could not find anything in the documentation about how these URIs (types) relate to those legacy error codes.
Also RFC7807 states that:

"detail" (string) - A human-readable explanation specific to this occurrence of the problem.

But in the API we get this response back:
"detail": "Unable to complete Authorization transaction, look at problem node!",
This is hardly human readable.

Also: The problems property contains an array of error objects. How should we interpret these? E.g. can there be multiple errors? Which of them should we report back to the users/customers? The description property looks like a concatenation of the old failedErrorCode and failedErrorDescription:
"description": "REJECTED_BY_ACQUIRER_CARD_STOLEN-card stolen, response-code: 43"
Maybe this instead could be split up into multiple extension members so that it's less complex for the clients to interpret?

In summary what I really need is:

  1. A list of the most common type URI's that we can expect. E.g. something similar to the list of legacy error code (https://developer.swedbankpay.com/resources/test-data#amount-error-testing-method).
  2. An easy way to find a human readable description of the error to display to the customers (on web or email).
  3. An implementation of these problem properties in the .NET SDK.
    You have already invited me to implement this myself and then do a pull request again.
    But it's a bit hard for me to do because you have supplied no documentation for the extension members you will be using. And it's also a bit hard to explain to our employer that we are spending time implementing an SDK that is owned by Swedbank.

Support unknown operations from API

Currently if a operation is not in the SDK we crash on TypedSafeEnumValueConverter when trying to read from JSON.
The SDK should either ignore it, or add it as an unknown type. Searching for operations on the string name is already supported (if I remember correctly) and as such it should be possible to add it as a unknown enum type to the list of operations.

EmailAddress class validation not conforming to RFC

Having an issue with the EmailAddress class that validates in its ctor.
The regex that is used seems to not conform to RFC https://tools.ietf.org/html/rfc2822#section-3.2.4.
For example:
[email protected] validates but [email protected] does not validate, but both are valid email addresses according to spec.

I've tried with a few other email variants and it does seem that most special characters that can be used in emails cant be used at the start or end of the local-part of the email. Trying with Postman against the service directly (POST https://api.externalintegration.payex.com/psp/paymentorders) there doesn't seem to be any validation for the email. So perhaps the validation is not needed or could be turned of perhaps?

Trying to omit the Email from the RiskIndicator class for example causes a null pointer exception.

I was thinking about perhaps usage of new EmailAddressAttribute().IsValid() but it really doesn't do anything more than just checks that a @ is included and something at all is before and something is after the @. So that could be to "little" validation if there should be something.

Remove Moq

We don't want it, it needs to be gone for we like NSubstite that we also have referenced in our configs.

SwedbankPay.Sdk.Extensions -> SwedbankPay.Sdk.NotPacked?

Hello,

There is a dependency on the SwedbankPay.Sdk.Extensions package for SwedbankPay.Sdk.NotPacked >= 4.0.0 that Im not able to resolve.

Error from a new project when trying to install after installed SwedbankPay.Sdk 4.0.0

Severity Code Description Project File Line Suppression State
Error NU1101 Unable to find package SwedbankPay.Sdk.NotPacked. No packages exist with this id in source(s): C:\Program Files\dotnet\library-packs, Microsoft Visual Studio Offline Packages, nuget.org TestSdk C:\GIT\Dev\TestSdk\TestSdk.csproj 1

unable to create a verify request

Hi
We are trying to add the possibility of recurring payments but are not successful with today's sdk.

According to the documentation, you should use this api
https://developer.swedbankpay.com/payment-instruments/card/features/optional/recur#verify

To get a RecurrenceToken.

swedbankPayClient.Payments.CardPayments.Create
This only has the following interface:

Task Create(CardPaymentRequest paymentRequest, PaymentExpand paymentExpand = PaymentExpand.None);

    Task<ICardPaymentResponse> Get(Uri id, PaymentExpand paymentExpand = PaymentExpand.None);

    Task<ICardPaymentRecurResponse> Create(CardPaymentRecurRequest paymentRequest, PaymentExpand paymentExpand = PaymentExpand.All);

    Task<ICardPaymentVerifyResponse> Create(CardPaymentVerifyRequest paymentRequest, PaymentExpand paymentExpand = PaymentExpand.All);

Where it is then thought that we should use the last one with CardPaymentVerifyRequest

But this cannot be used as it lacks the flag to request token for recurring payment.

cardRequest.Payment.GenerateRecurrenceToken = true;

and if you ignore this and try with this anyway, you will get a crash in the function
public CardPaymentVerifyRequestDetailsDto(CardPaymentVerifyRequestDetails payment)

on the line
Amount = payment.Amount.InLowestMonetaryUnit;
then amount is always null as it has no set.

Thankful for any hint if we are using the wrong api.
//Regards Joacim

Feedback

I have been testing the SDK and have following feedback and suggestion for improvements:

  1. The current code does not allow us to deliberately re-use code for Payments instruments. An example is PaymentsResource.cs where the methods for getting and creating payments are close to identical. This should be abstracted so there is only need for getpayment and createpayment.
  2. In src/SwedbankPay.Sdk/SwedbankPayHttpClient.cs:
    The SwedbankPayHttpClient class is made internal although GET, POST, and PATCH methods could be useful other places.
  3. The readme.md does not provide necessary information for a basic implementation. It would be helpful for the users to have a beginner's manual in order to get started with an implementation.

Operations design

This issue is for discussion of an operations design, so that we retain the functionality provided by our APIs with a list of dynamically available operations, so the state management of operation availability is preserved by the server and not moved up into the client.

Support unknown enums

Currently I get errors because the api returns new types of PriceType.
The SDK should/must support having unknown enums so when types are added to the api the SDK does not break down.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.