Datatrans payment system with JSinterop

81 views
Skip to first unread message

pierre...@gmail.com

unread,
Jan 21, 2021, 3:19:48 AM1/21/21
to GWT Users
Hi,

I am trying to integrate the Datatrans payment system with JSinterop

the js code to be executed should be :

payButton.onclick = function() {
  Datatrans.startPayment({
    transactionId:  "{{transactionId}}",
    'opened': function() {console.log('payment-form opened');},
    'loaded': function() {console.log('payment-form loaded');},
    'closed': function() {console.log('payment-page closed');},
    'error': function() {console.log('error');}
  });
};

I created a Datatrans class :

@JsType(namespace = JsPackage.GLOBAL, isNative = true)
public class Datatrans {
public native static void startPayment(String transactionId);
}

When clicking on the payButton, the startPayment function from the js code is executed but no dialog from datastrans is shown.
I guess imy definition of my startPayment method doesnot include the functions callbacks for opened/loaded etc
How can I define these functions and change my  startPayment definition ?

Thanks in advance for any help
Pierre

pierre...@gmail.com

unread,
Jan 21, 2021, 7:07:34 AM1/21/21
to GWT Users
I was able to make it work using a DatatransOption class for the config :
@JsType(namespace = JsPackage.GLOBAL, name = "Object", isNative = true)
public class DatatransOption {

 @JsProperty
public String transactionId;
@JsProperty
public Func opened;
...
@JsOverlay
public static DatatransOption create(String transactionId)
{
DatatransOption option = new DatatransOption();
option.transactionId = transactionId;
option.opened = new Func() {
@Override
public void call() {
Window.alert("payment-form opened ");
}
};
...
return option;
}




The Func interface is from Gwt-Material

Thomas Broyer

unread,
Jan 21, 2021, 12:51:57 PM1/21/21
to GWT Users
You could probably also use a non-native type:

public class DatatransOption {
  @JsProperty
  public String transactionId;
  
  @JsMethod
  public void opened() {
    Window.alert("payment form opened");
  }
}

pierre...@gmail.com

unread,
Jan 22, 2021, 2:35:42 AM1/22/21
to GWT Users
Thanks Thomas,

I tried it but the compiler is complaining :
            [ERROR] Line 27: Native JsType method 'void DatatransOption.opened()' should be native or abstract.
As I would like to implement them myself, is there a workaround ?  

Pierre
Reply all
Reply to author
Forward
0 new messages