GithubHelp home page GithubHelp logo

datatrans / react-datatrans-light-box Goto Github PK

View Code? Open in Web Editor NEW
10.0 10.0 7.0 974 KB

Lightweight React wrapper for Datatrans Payment Lightbox

Home Page: https://www.npmjs.com/package/react-datatrans-light-box

JavaScript 36.43% HTML 10.32% TypeScript 53.25%
react javascript datatrans

react-datatrans-light-box's Introduction

NPM version CI

Datatrans React Light Box

Official Datatrans light box library for showing our payment page in React applications. React is defined as a peer dependency and expected to be made available by your project. Other than that this library is completely dependency-free.

Compatibility

Beginning with v3.0.0, this component is using the Datatrans Payment JSON API.

If you're still using the legacy XML API, please refer to react-datatrans-light-box v2.0.2.

How to install

# Use with current JSON API
npm install react-datatrans-light-box

# Use with legacy XML API (supported by react-datatrans-light-box <= 2.x)
npm install react-datatrans-light-box@2

Example usage

import React, { useState } from 'react'
import Lightbox from 'react-datatrans-light-box'

export default (props) => {
  const { transactionId } = props

  const [lightbox, showLightbox] = useState(false)

  const onLoaded = () => console.log('Loaded')
  const onOpened = () => console.log('Opened')
  const onCancelled = () => showLightbox(false)
  const onError = (data) => {
    console.log('Error:', data)
    showLightbox(false)
  }

  return <div>
    <h1>Datatrans Lightbox Demo</h1>
    <div>
      {lightbox
        ? <Lightbox
            transactionId={transactionId}
            production={true}
            onLoaded={this.onLoaded}
            onOpened={this.onOpened}
            onCancelled={this.onCancelled}
            onError={this.onError}
          />
        : <button onClick={() => showLightbox(true)}>Start Lightbox</button>
      }
    </div>
  </div>
}

Properties

The Lightbox component takes the following properties as input.

Property Mandatory Type Description
transactionId Yes String Transaction ID returned by Initializing Transactions.
production No Boolean Indicates whether requests hit Datatrans' production or sandbox environment. Defaults to false (sandbox).
onLoaded No Function Called when payment page is loaded.
onOpened No Function Called when payment page is opened.
onCancelled No Function Called when user has cancelled payment.
onError No Function Called when there was an error loading the payment page.

react-datatrans-light-box's People

Contributors

benji24290 avatar fgrdtrx avatar jantimon avatar jlgeering avatar kevingruber avatar mephju avatar n3ssi3 avatar pstadler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-datatrans-light-box's Issues

Error with themeConfiguration Params

Hi guys! Me again.
I found a new issue when passing themeConfiguration param as Lightbox props.

const settings = {
            useAlias: true,
            < ... other params ...>
            themeConfiguration: { brandColor: '#444444', logoType: 'none', brandTitle: 'none' },
        };

<Ligthbox ...settings />

And the requested url to raise the lightbox modal is

https://pilot.datatrans.biz/upp/jsp/upStart.jsp?useAlias=true&<...other params...>&themeConfiguration=%5Bobject%20Object%5D

I think the problem is again in src/utils.js line 18 => export const toUrlParams. The function doesn't know how to handle the themeConfiguration object.

Could someone help me with this?
Thanks in advance guys.

You really did a great work.

accessibility bugs of lightbox overlay

After integration of datatrans lightbox our accessibility test results in different problems related to the usage of that lightbox:

  • Inputs are not accessible in linear direction top down
  • in high contrast mode the light box has no visible frame
  • focus styling is not strong enough and only slightly visible
  • error message are not related to the payment method -> generic messages used
  • focus of page, which embeds lightbox, is reseted -> original focused element is not refocused after closing box
  • page scroll position is not correctly restored after closing lightbox

Error with paymentmethod attribute

Hi Guys! Congrats for this library. We're using it in a full react application. I found an issue when passing the paymentmethod parameters.
I tried to pass them in two different ways

<Ligthbox paymentmethod="VIS,JCB,AMX" ... /> and
<Ligthbox paymentmethod={["VIS", JCB, AMX]} ... />

The upStart.jsp endpoint requires multiple pamymentmethos query parameters as is shown below
https://pilot.datatrans.biz/upp/jsp/upStart.jsp?<other_query_string_params>&paymentmethod=VIS&paymentmethod=AMX&paymentmethod=ECA

But the function toUrlParams, located in src/utils.js line 18

export const toUrlParams = props => Object.keys(props)
.map(key => `${key}=${props[key]}`)
.join('&')

isn't handle them correctly.

Could you help me with this?
Thanks in advance.

doesn't work if requireJS is on the page

hi!

the react-datatrans-light-box integration fails if a define function is attached to the window because of the umd wrapper is used in datatrans:

amd

would it be possible to bundle datatrans right into this package?

const getDatatrans = (production) => 
  production 
     ? import('./datatrans-2.0.0.min.js')
     : import('./sandbox-datatrans-2.0.0.min.js')
}

Cannot read properties of undefined (reading 'startPayment')

Hi Datatrans,

Thanks a bunch for this library and the quick integration into React.

I am facing an issue where I am getting an error message, followed by the lightbox appearing a couple seconds later.

Screenshot 2022-10-05 at 16 04 53

Screenshot 2022-10-05 at 16 05 29

If I integrate the script given in the datatrans documentation (<script src="https://pay.sandbox.datatrans.com/upp/payment/js/datatrans-2.0.0.js">), the lightbox shows up but I cannot click anywhere on the lightbox

I am currently building a Web Application with :
Nextjs v 12.3.0
React v 18.2.0
react-datatrans-light-box v 3.1.0

Can no more scroll or click on the page after onSuccess

Hi,

after placing an order and being redirected to the order success page, I cannot click or scroll anymore.
Inspecting the dom, I can see that some styles set on the body and html (eg. overflow hidden) elements are not removed .
Also, data property 'data-datatrans-payment-lock' is still set to 'locked' on the html element.
Besides, the element 'paymentFrameWrapper' is set as 'display: block' with an overflow hidden.

In console I am getting,

VM298093 onloadwff.js:58 Uncaught TypeError: Cannot read property 'teardown' of undefined at Object.o.teardown (onloadwff.js:58) at onloadwff.js:58

I googled a bit and it seems something related to lastpass chrome extension. I re-tested in incognito mode but still same. Cannot click nor scroll.

Idea?

PS: I upgraded to 2.0.1, removed usage of HoC

SuccessUrl Redirect problem

After the payment is completed successfully, I cannot redirect to the page I want. When I add the successUrl parameter, it forces it to use with the post method.
After the payment is completed, it is directed to this page.
https://icctest.sunnyclient.com/payment/confirm.php
Is there a solution for this?

UPDATE: I think this solved my problem

<Lightbox {...config} onLoaded={onLoaded} onOpened={onOpened} onCancelled={onCancelled} onError={onError} onSuccess={onSuccess} successUrl={ "http://localhost:3000/success-payment" } uppWebResponseMethod={"GET"} />

OnSuccess callback missing

Hello,

we are working with the datatrans lightbox and we need a "real" callback (not just a redirect URL) after a successful payment method cause we are using the lightbox inside an iframe webshop without access to the wrapper host page.

Please help. Thank you!

Error while parsing the 'sandbox' attribute: 'null' is an invalid sandbox flag.

Hi guys!

One of our customers just ran into an issue which I can not reproduce at the moment:

(anonymous) @ datatrans-2.0.0.min.js:1

upStart.jsp:1 Blocked script execution in 'https://pay.datatrans.com/upp/jsp/upStart.jsp' because the document's frame is sandboxed and the 'allow-scripts' permission is not set.

upStart.jsp:76 Blocked script execution in 'https://pay.datatrans.com/upp/jsp/upStart.jsp' because the document's frame is sandboxed and the 'allow-scripts' permission is not set.

upStart.jsp:1 Blocked script execution in 'https://pay.datatrans.com/upp/jsp/upStart.jsp' because the document's frame is sandboxed and the 'allow-scripts' permission is not set.

After investigating the related file I found the attribute datatransPaymentConfig.sandboxAttributeEnabled which is disabled by default but seems to be responsible for setting the sandbox property. Is there a way to enable the required sandbox attributes using Lightbox component props or is that the intended behaviour?

Thanks for your help!

Config object params

I noticed that I cannot pass any config object to the Lightbox component anymore.

let config = {
transactionId: 'xxx-xxx-xxx-xxx',
refno: 'xxx-xxx-xxx',
amount: 5000,
currency: 'CHF',
production: false,
paymentMethod: ['ECA', 'VIS', 'TWI'],
autoSettle: true,
themeConfiguration: {
brandColor: '#FFD32F'
}
}

<Lightbox
{...config}
onLoaded={onLoaded}
onOpened={onOpened}
onCancelled={onCancelled}
onError={onError}
amount={500}
/>

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.