1.0.3 • Published 3 months ago

@noda-ui/open-banking v1.0.3

Weekly downloads
-
License
-
Repository
-
Last release
3 months ago

@noda-ui/open-banking

Installation

npm i @noda-ui/open-banking
#or
yarn add @noda-ui/open-banking

Usage

<body>
  <noda-open-banking-widget id="payment-widget"><noda-open-banking-widget>
</body>
import "@noda-ui/open-banking/lib/index.js";
import "@noda-ui/open-banking/lib/styles/styles.css";

const $payment = document.querySelector("#payment-widget");
const params: OpenBankingWidgetParams = {
    // * Required
    apiKey: string;
    amount: number;
    returnUrl: string;
    currency: string;
    paymentId: string;
    //  * Not Required
    language: OpenBankingLanguage;
    env: OpenBankingEnv;
    webhookUrl: string;
    shopId: string;
    description: string;
    customerId: string;
    email: string;
    iin: number;
    ipAddress: string;
    fullWidth: boolean;
    disabledPaymentButton: boolean;
    country: string;
}

$payment.initWithParams(params);

$payment.addEventListener("result", (event: OpenBankingResult) => {
  console.log("event after pay: ", event.detail); // OpenBankingResult
});


// * If you need change params

$payment.setParams(params: OpenBankingPaymentParams)

#or

const paramKey: keyof OpenBankingPaymentParams = 'amount';
const paramValue: typeof OpenBankingPaymentParams['amount'] = 100
const isRestartPayment: boolean = false;

$payment.setParam(paramKey, paramValue, isRestartPayment)

OpenBankingWidgetParams

FieldTypeDescriptionDefault
apiKey *requiredstringMerchant's api key, issued by Nodanull
amount *requirednumberPayment amountnull
returnUrl *requiredstringAfter the payment completed, customer will be redirected into this Urlnull
currency *requiredstringPayment currency in ISO_4217 format.null
paymentId *requiredstringOrder identificator in merchant's systemnull
languageOpenBankingLanguageWidget Language"en"
envOpenBankingEnvApp environments, for develop and production. Currently accepted: {PRODUCTION, DEVELOPMENT}"PRODUCTION"
skipRedirectbooleanRedirect to "returnUrl" after payment result eventfalse
webhookUrlstringURL where the Noda will send hooks about the payment status changesnull
shopIdstringMerchant's shop identificator, issued by Noda. If you have more than one online shop, this parameter helps to analyse the payments afterwardsnull
descriptionstringShort order description for the customernull
customerIdstringEnd-customer Id in merchant's system. That parameter can be used to find a best button appearance for the particular customer.null
emailstringEnd-customer e-mail. That parameter can be used to find a best button appearance for the particular customer.null
iinnumberIIN (first six digits) of the end-customers credit card used earlier at the merchant's checkout. This parameter helps to define end-customer Bank and propose to pay with that bank.null
ipAddressstringEnd-customer IP Address. That parameter can be used to detect a customer's country (for example, for EUR payments - Spain, Germany, France etc.)null
fullWidthbooleanFull width on screen for payment buttonfalse
disabledPaymentButtonobjectDisabled payment buttonfalse
countryobjectISO 3166-1 alpha-2 country codenull

OpenBankingResult

FieldTypeDescription
idstringPayment identificator in Noda system
result'done' | 'failed' | 'awaiting confirmation'Payment status
signaturestringSignature: sha256(id+status+signatureKey)

Output events

EventTypeDescription
resultOpenBankingResulttriggered after receiving a payment response

Library types

type OpenBankingEnv = 'PRODUCTION' | 'DEVELOPMENT';
type OpenBankingLanguage = 'en' | 'de' | 'es' | 'fr';
interface OpenBankingPaymentParams {
  amount?: number;
  returnUrl?: string;
  currency?: string;
  paymentId?: string;
  webhookUrl?: string;
  shopId?: string;
  description?: string;
  customerId?: string;
  email?: string;
  iin?: number;
  ipAddress?: string;
  country?: string;
}

Payment Result handling

You can receive payment result with the following options:

  • Parameters in returnUrl After the payment completed, customer will be redirected into returnUrl with the Payment Result parameters in query string:
https://{domain}?id=63c507d9-4f19-46d0-ac37-5b7d4f6fe040&result=done&signature=6ec13bda02080a4006223c1ba9d8fa97e2de0a1ca782d95d63f4b69789117cc6
  • Receive a hook into webhookUrl If you passed webhookUrl earlier, you will receive the hook as POST request with the Payment Result parameters as JSON body (example):
{
    id: "63c507d9-4f19-46d0-ac37-5b7d4f6fe040",
    result: "done",
    signature: "6ec13bda02080a4006223c1ba9d8fa97e2de0a1ca782d95d63f4b69789117cc6"
}

For the returnUrl and webhookUrl handling methods, make sure to implement the proper payment control procedures

Control procedures

If you're using returnUrl and/or webhookUrl for the results handling, it is mandatory to implement a simple control procedure in order to prevent fraudulent behaviour. After receiving the results you will need to do the following:

  • Verify the payment signature parameter The signature can be verified with the following algorythm:
signature == sha256(id + status + signatureKey);
  • Check the duplicates of signatures

    You will need to make sure the payment result belongs to the concrete order you are about to proceed. Intruders can not create a valid Signature unless they know your SignatureKey. However, they can intercept the result message and then re-use its Signature. In order to prevent this action, you will need to implemenent anti-duplication control algorythm. For example, you can compare the paymentId of the current order and in the payment result.

Security

Remember to use valid api token for apiKey field.

How to obtain the keys?

Sanodaox: use 24d0034-5a83-47d5-afa0-cca47298c516 for DEVELOPMENT environment. Live: use 808e683e-9383-4717-8148-02e74b63b1f8 for testing purposes.

Please consider, that this is a real payment routing which is set up to charity organisations complete the onboarding at ui.noda.live/hub to get your production keys

Payment UX

Please switch the "Purchase scenarios" at ui.noda.live/demo in order to overview the different behavior.

If you've used some additional parameters (for example - IP, IIN, CustomerID and so on) previosly, for the same purchase, we highly recommend pass the same additional parameters, in order to keep the consistent UX for the customers.

Webpack 5 Issues

During the integration process, you might face multiple issues with webpack 5. This issue is caused due to the fact that some packages have certain dependencies, which are not present within the browser environment by webpack 5. Hence, you require certain node polyfills to be added to your project, while overriding the configurations to enable their usage. When that is done, your project should run without any issues.

An alternative solution to the problem is to install @microsoft/signalr package in your project.

Alternative Payment Result

Please see the detailed description at docs.noda.live.