globalpayments / globalpayments-js

JavaScript library for web applications to connect to Heartland eCommerce & Global Payments eCommerce tokenization services
14 stars 23 forks source link

Error when importing from globalpayments-js module #17

Open andrii-kryvoviaz opened 4 years ago

andrii-kryvoviaz commented 4 years ago

Hi. I was trying to import your library and implement the demo example.

image

Here is what I got: ERROR in node_modules/globalpayments-js/types/global-type.d.ts(1,17): error TS2307: Cannot find module './'.. Is there any solution?

Btw, are you going to publish the package to NPM?

andrii-kryvoviaz commented 4 years ago

Please review #18.

slogsdon commented 4 years ago

Hi @AndyKrivovjas! Thanks for sending this over. We have been investigating our options for delivering the JS library via NPM, and the current thought is to deploy a loader to NPM that asynchronously loads the library and includes the library's TypeScript type declarations. This is to retain the PCI-DSS benefits from hosting the library on our servers.

If interested, you can achieve the loading side of this effort with the below code:

// @ts-check

/**
 * Latest version deployed on the gateway
 */
const DEFAULT_VERSION = "1.3.0";

/**
 * Global load flag to help prevent double loading
 */
let flag = false;

/**
 * Creates a new `script` element on the page to load the Global Payments JS library.
 * 
 * Default version is `1.0.1`. Default callback performs no action. 
 * 
 * Examples:
 * 
 *   - `load();`
 *   - `load("1.0.0");`
 *   - `load("1.0.0", () => console.log("loaded"));`
 *   - `load(() => console.log("loaded"));`
 *
 * @param {string | Function} [versionOrCallback] Supply a version number to override the default
 * @param {Function} [callback] Supply a callback in order to react to the library loading onto the page
 */
function load(versionOrCallback, callback) {
  // allow a callback to be passed in without a version
  if (versionOrCallback instanceof Function && callback === undefined) {
    callback = versionOrCallback;
    versionOrCallback = DEFAULT_VERSION;
  }

  // wrap the callback to ensure it's callable
  const cb = () => callback && callback();

  // return earlier if we've already loaded the script
  if (flag) {
    cb();
    return;
  }

  const script = document.createElement("script");
  script.src = "https://api2.heartlandportico.com/securesubmit.v1/token/gp-" + versionOrCallback + "/globalpayments.min.js";
  // try not to block rendering
  script.defer = true;
  script.onload = () => {
    flag = true;
    cb();
  };
  document.getElementsByTagName("head")[0].appendChild(script);
}

/**
 * Allow default version to be read by the integrator
 */
load.defaultVersion = DEFAULT_VERSION;

module.exports = load;
andrii-kryvoviaz commented 4 years ago

@slogsdon It would be great if you publish such package to NPM.

One more thing. I was playing around with your library lately and I couldn't find how to connect the JS library with php-sdk. https://developer.globalpay.com/#!/hpp/card-payments#hpp-authorization

I recall when it was Realexpayments there were three parameters to the library:

  1. HPP Request url;
  2. Gateway url;
  3. HPP Response url.

1 and 3 were handled by php-sdk. Now it doesn't seem to work this way. Where can I find the relevant documentation in order to implement global payments solution both backend and frontend?

slogsdon commented 4 years ago

@AndyKrivovjas This JS library doesn't yet support the full GP eCommerce / Realex HPP. It uses the HPP's Direct Post option under the hood to vault the card, so 1 and 3 are handled automatically for you.

If you're looking to leverage the full GP eCommerce HPP, you'll want to use the legacy rxp-js library on the frontend. You could then reference the documentation on how to configure the SDK to create the HPP request and parse the response.

andrii-kryvoviaz commented 4 years ago

@slogsdon Are you planning adding support for it?

The legacy library isn't much extendable either. It requires an html element to work; I cannot run it directly from the code.

slogsdon commented 4 years ago

Yes, we'd like to add support for the GP eCommerce HPP within this library, although we don't currently have an ETA for this work.