Source: transpayrent-ui-helper.js

  1. /**
  2. * @copyright Transpayrent ApS 2022
  3. * @license Common Transpayrent API license
  4. * @version 1.2.0
  5. *
  6. * @class
  7. * @classdesc The Transpayrent UI Helper SDK simplifies completion of the entire payment process into the following 3 steps:
  8. * 1) Override UI Helper SDK methods to return the correct request for the specified payment method:
  9. * * [Create Payment Transaction]{@link TranspayrentUIHelper#getCreateTransactionRequest}
  10. * * [Initialize Payment]{@link TranspayrentUIHelper#getInitializePaymentRequest}
  11. * * [Authenticate Consumer]{@link TranspayrentUIHelper#getAuthenticateConsumerRequest}
  12. * * [Authorize Payment]{@link TranspayrentUIHelper#getAuthorizePaymentRequest}
  13. * * [Save]{@link TranspayrentUIHelper#getSaveRequest}
  14. * 2) Construct requests for each operation: createTransaction, initialize, authenticate, authorize and save
  15. * 3) Call the [Complete the Payment using the Transpayrent UI Helper SDK]{@link TranspayrentUIHelper#completePayment}
  16. *
  17. * @see [TranspayrentUIHelper]{@link TranspayrentUIHelper}
  18. * @see {@link TranspayrentUIHelper#getCreateTransactionRequest}
  19. * @see {@link TranspayrentUIHelper#getInitializePaymentRequest}
  20. * @see {@link TranspayrentUIHelper#getAuthenticateConsumerRequest}
  21. * @see {@link TranspayrentUIHelper#getAuthenticateConsumerRequest}
  22. * @see {@link TranspayrentUIHelper#getAuthorizePaymentRequest}
  23. * @see {@link TranspayrentUIHelper#getSaveRequest}
  24. * @see {@link TranspayrentUIHelper#displayStatusMessage}
  25. * @see {@link TranspayrentUIHelper#displayAuthenticationFailure}
  26. * @see {@link TranspayrentUIHelper#displayPaymentConfirmation}
  27. *
  28. * @constructor
  29. * @description Creates a new instance of the Transpayrent UI Helper SDK, which uses the Transpayrent SDK internally to handle the secure communication with Transpayrent's Payment Gateway.
  30. * @example <caption>Instantiate the Transpayrent SDK and Transpayrent UI Helper SDK</caption>
  31. * <script src="https://storage.googleapis.com/static.[ENVIRONMENT].transpayrent.cloud/v1/swagger-client.js"></script>
  32. * <script src="https://storage.googleapis.com/static.[ENVIRONMENT].transpayrent.cloud/v1/transpayrent.js"></script>
  33. * <script>
  34. * // Override UI Helper SDK methods to return the correct request for the specified payment method
  35. * TranspayrentUIHelper.prototype.getCreateTransactionRequest = function (paymentMethodId) {
  36. * return createTransactionRequests[paymentMethodId];
  37. * }
  38. * TranspayrentUIHelper.prototype.getInitializePaymentRequest = function (paymentMethodId) {
  39. * return initializePaymentRequests[paymentMethodId];
  40. * }
  41. * TranspayrentUIHelper.prototype.getAuthenticateConsumerRequest = function (paymentMethodId) {
  42. * return authenticateConsumerRequests[paymentMethodId];
  43. * }
  44. * TranspayrentUIHelper.prototype.getAuthorizePaymentRequest = function (paymentMethodId) {
  45. * return authorizePaymentRequests[paymentMethodId];
  46. * }
  47. * TranspayrentUIHelper.prototype.getSaveRequest = function (paymentMethodId) {
  48. * return saveRequests[paymentMethodId];
  49. * }
  50. *
  51. * // SDK configuration
  52. * const transpayrentConfig = {
  53. * merchantId: [UNIQUE MERCHANT ID ASSIGNED BY TRANSPAYRENT],
  54. * sessionId: [ID IN THE RESPONSE FROM "Create Payment Session"],
  55. * accessToken: '[x-transpayrent-access-token HTTP HEADER IN THE RESPONSE FROM "Create Payment Session"]'
  56. * };
  57. * const url = 'https://generator.[ENVIRONMENT].transpayrent.cloud/v1/'+ transpayrentConfig.merchantId +'/system/PAYMENT_GATEWAY/sdk/CLIENT';
  58. *
  59. * // Instantiate SDK and UI Helper SDK
  60. * const sdk = new Transpayrent(url, transpayrentConfig);
  61. * const helper = new TranspayrentUIHelper(sdk, document.getElementById('container'), document.getElementById('loader') );
  62. *
  63. * // Construct requests for each operation: createTransaction, initialize, authenticate, authorize and save
  64. * var card = { card_number: 4111111111111111, // Successful Authorization: Manual Challenge with browser fingerprint
  65. * expiry_month: 9,
  66. * expiry_year: 22,
  67. * cvv: 987,
  68. * card_holder_name: 'John Doe',
  69. * save: true };
  70. * card.payment_method_id = sdk.getPaymentMethodId(card.card_number);
  71. * var address = { street : 'Arne Jacobsens Allé 7',
  72. * appartment : '5. sal',
  73. * city : 'Copenhagen S',
  74. * postal_code : '2300',
  75. * state : '82',
  76. * country: 208 }; // Denmark
  77. * var phone = { international_dialing_code: 45, // Denmark
  78. * phone_number: 89671108 };
  79. * var email = 'hello@transpayrent.dk';
  80. *
  81. * var createTransactionRequests = new Array();
  82. * // Card based payment
  83. * createTransactionRequests[card.payment_method_id] = { correlation_id : 'TP-'+ transpayrentConfig.sessionId,
  84. * amount: { currency : 208, // DKK
  85. * value : card.save ? 0 : 100 } };
  86. * // Transpayrent - Consumer Wallet
  87. * createTransactionRequests[201] = { correlation_id : 'TP-'+ transpayrentConfig.sessionId,
  88. * amount: { currency : 208, // DKK
  89. * value : 100 } };
  90. * // MobilePay Online
  91. * createTransactionRequests[202] = { correlation_id : 'TP-'+ transpayrentConfig.sessionId,
  92. * amount: { currency : 208, // DKK
  93. * value : 100 } };
  94. *
  95. * var initializePaymentRequests = new Array();
  96. * // Card based payment
  97. * initializePaymentRequests[card.payment_method_id] = { payment_method_id : card.payment_method_id }
  98. * // Consumer Wallet
  99. * initializePaymentRequests[201] = { payment_method_id : 201 }
  100. * // MobilePay Online
  101. * initializePaymentRequests[202] = { payment_method_id : 202,
  102. * mobile : phone,
  103. * save : false };
  104. *
  105. * var authenticateConsumerRequests = new Array();
  106. * // Card based payment
  107. * authenticateConsumerRequests[card.payment_method_id] = { payment_details : card,
  108. * billing_address : address,
  109. * shipping_address : address,
  110. * contact : { mobile : phone,
  111. * work : phone,
  112. * home : phone,
  113. * email : email } };
  114. *
  115. * var authorizePaymentRequests = new Array();
  116. * // Card based payment
  117. * authorizePaymentRequests[card.payment_method_id] = { payment_details : card };
  118. * // Consumer Wallet
  119. * authorizePaymentRequests[201] = { payment_details : { payment_method_id : 201,
  120. * valuable_id : [VALUEABLE ID IN THE RESPONSE FROM "Create Payment Session"],
  121. * access_token : '[MERCHANT'S SINGLE SIGN-ON TOKEN FOR AUTHORIZING A PAYMENT WITH THE CONSUMER'S WALLET]' } };
  122. * // MobilePay Online
  123. * authorizePaymentRequests[202] = { payment_details : { payment_method_id : 202 } };
  124. *
  125. * var saveRequest = { payment_details : card,
  126. * consumer_id : '[MERCHANT'S CONSUMER ID FROM PAYMENT SESSION]',
  127. * name : "My VISA Card" }
  128. *
  129. * // Complete the payment using the UI Helper SDK
  130. * var paymentMethodId = 201; // Consumer Wallet
  131. * helper.completePayment(paymentMethodId, card.save);
  132. * </script>
  133. *
  134. * @param {Transpayrent} sdk The instance of the Transpayrent SDK, which will be used by the UI Helper
  135. * @param {Element} container The container element in which the constructed iframe for initializing a payment with a 3rd party wallet such as MobilePay or authenticating the consumer using 3D Secure will be displayed. Defaults to `document.body`.
  136. * @param {Element} loader The loading indicator element
  137. */
  138. function TranspayrentUIHelper(sdk, container, loader) {
  139. /**
  140. * The instance of the Transpayrent SDK, which will be used by the UI Helper
  141. *
  142. * @private
  143. *
  144. * @type {Transpayrent}
  145. */
  146. this._sdk = sdk;
  147. /**
  148. * The container element in which the constructed iframe for initializing a payment with a 3rd party wallet such as MobilePay or authenticating the consumer using 3D Secure will be displayed. Defaults to `document.body`.
  149. *
  150. * @private
  151. *
  152. * @type {Element}
  153. */
  154. this._container = container;
  155. /**
  156. * The loading indicator element
  157. *
  158. * @private
  159. *
  160. * @type {Element}
  161. */
  162. this._loader = loader;
  163. /* ========== COMMON METHODS START ========== */
  164. /**
  165. * A representation of the configuration for completing the consumer's payment
  166. *
  167. * @property {boolean} disable_authentication Boolean flag specifying whether Strong Consumer Authentication (SCA) should be disabled.
  168. * Explicitly disabling SCA is useful for Mail Order / Telephone Order (MOTO) transactions.
  169. *
  170. * @typedef {Object} Configuration
  171. */
  172. /**
  173. * Completes the consumer's payment by executing the following steps:
  174. * 1) Create a payment transaction with the specified payment method
  175. * 2) Initialize the payment for the specified payment method
  176. * 3) Complete Strong Consumer Authentication (SCA) using 3D Secure if applicable
  177. * 4) Authorize the payment for the payment transaction using the specified payment method
  178. *
  179. * @see {@link Transpayrent#createTransaction}
  180. * @see {@link Transpayrent#initialize}
  181. * @see {@link Transpayrent#authenticate}
  182. * @see {@link Transpayrent#authorize}
  183. * @see {@link Transpayrent#save}
  184. * @see {@link TranspayrentUIHelper#displayStatusMessage}
  185. * @see {@link TranspayrentUIHelper#displayAuthenticationFailure}
  186. * @see {@link TranspayrentUIHelper#displayPaymentConfirmation}
  187. * @see {@link TranspayrentUIHelper#getCreateTransactionRequest}
  188. * @see {@link TranspayrentUIHelper#getInitializePaymentRequest}
  189. * @see {@link TranspayrentUIHelper#getAuthenticateConsumerRequest}
  190. * @see {@link TranspayrentUIHelper#getAuthorizePaymentRequest}
  191. * @see {@link TranspayrentUIHelper#getSaveRequest}
  192. * @see {@link TranspayrentUIHelper#getIFrameConfig}
  193. *
  194. * @param {PAYMENT_METHOD_ID} paymentMethodId The payment method selected by the consumer
  195. * @param {boolean} save Boolean flag indicating whether the payment details for the specified payment method will be saved
  196. * @param {Configuration} config Configuration for completing the consumer's payment
  197. */
  198. TranspayrentUIHelper.prototype.completePayment = function (paymentMethodId, save, config) {
  199. if (save == null) {
  200. save = this.getInitializePaymentRequest(paymentMethodId).save;
  201. }
  202. config = Object.assign({ disable_authentication : false },
  203. config);
  204. if (this._container) {
  205. this._container.style.visibility = 'visible';
  206. }
  207. var request = this.getCreateTransactionRequest(paymentMethodId);
  208. var token = null;
  209. const amount = request.amount;
  210. this._sdk.createTransaction(paymentMethodId, request)
  211. .then(
  212. transaction => {
  213. // Creation of Payment Transaction failed - Display status message
  214. if (transaction.status) {
  215. this.displayStatusMessage(transaction);
  216. return Promise.reject(null);
  217. }
  218. else {
  219. var cfg = this.getIFrameConfig('payment-initialization');
  220. if (cfg.container) {
  221. this._sdk.clearContainer(cfg.container);
  222. }
  223. return this._sdk.initialize(transaction.id, this.getInitializePaymentRequest(paymentMethodId), cfg);
  224. }
  225. })
  226. .then(
  227. initialization => {
  228. // Initialization of Payment Transaction failed - Display status message
  229. if (initialization.status) {
  230. this.displayStatusMessage(initialization);
  231. return Promise.reject(null);
  232. }
  233. else {
  234. // Token returned by a 3rd party wallet such as Apple Pay or Google Pay
  235. if (initialization.hasOwnProperty('token') ) {
  236. token = initialization.token;
  237. }
  238. // Redirect or App-Switch
  239. if (initialization.connection && initialization.connection.action <= 2) {
  240. window.location.href = initialization.connection.url;
  241. }
  242. // Payment Transaction is exempt from Strong Consumer Authentication (SCA) or SCA disabled
  243. else if (this._sdk.isSCAExempt(paymentMethodId, amount, save) || config.disable_authentication) {
  244. return Promise.resolve(initialization);
  245. }
  246. else {
  247. request = this.getAuthenticateConsumerRequest(paymentMethodId);
  248. // Perform Strong Consumer Authentication (SCA)
  249. if (request) {
  250. // Use token returned by a 3rd party wallet such as Google Pay for strong consumer authentication
  251. if (token) {
  252. request.payment_details.token = token;
  253. }
  254. var cfg = this.getIFrameConfig('consumer-authentication');
  255. if (cfg.container) {
  256. this._sdk.clearContainer(cfg.container);
  257. }
  258. return this._sdk.authenticate(initialization.transaction_id, request, cfg);
  259. }
  260. // Strong Consumer Authentication (SCA) not available for Payment Method
  261. else {
  262. return Promise.resolve(initialization);
  263. }
  264. }
  265. }
  266. })
  267. .then(
  268. authentication => {
  269. // Consumer Authentication failed
  270. if (authentication.status) {
  271. // Consumer Authentication failure
  272. if (authentication.status == 511) {
  273. this.displayAuthenticationFailure(authentication);
  274. }
  275. // API request failed - Display status message
  276. else {
  277. this.displayStatusMessage(authentication);
  278. }
  279. return Promise.reject(null);
  280. }
  281. // Payment Transaction is exempt from Strong Consumer Authentication (SCA) or SCA disabled
  282. else if (this._sdk.isSCAExempt(paymentMethodId, amount, save) || config.disable_authentication) {
  283. request = this.getAuthorizePaymentRequest(paymentMethodId);
  284. // Use token returned by a 3rd party wallet such as Apple Pay or Google Pay for payment authorization
  285. if (token) {
  286. if (request.hasOwnProperty('payment_details') ) {
  287. request.payment_details.token = token;
  288. }
  289. else {
  290. request.token = token;
  291. }
  292. }
  293. return this._sdk.authorize(authentication.transaction_id, request);
  294. }
  295. // Consumer Authentication successfully completed: Save Payment Card
  296. else if (save) {
  297. request = this.getSaveRequest(paymentMethodId);
  298. // Use token returned by a 3rd party wallet such as Apple Pay or Google Pay for payment authorization
  299. if (token) {
  300. request.payment_details.token = token;
  301. }
  302. request.payment_details.cryptogram = authentication.cryptogram;
  303. return this._sdk.save(authentication.transaction_id, request);
  304. }
  305. // Consumer Authentication successfully completed: Authorize Payment
  306. else {
  307. request = this.getAuthorizePaymentRequest(paymentMethodId);
  308. if (request.hasOwnProperty('payment_details') ) {
  309. // Use token returned by a 3rd party wallet such as Apple Pay or Google Pay for payment authorization
  310. if (token) {
  311. request.payment_details.token = token;
  312. }
  313. request.payment_details.cryptogram = authentication.cryptogram;
  314. }
  315. else {
  316. // Use token returned by a 3rd party wallet such as Apple Pay or Google Pay for payment authorization
  317. if (token) {
  318. request.token = token;
  319. }
  320. request.cryptogram = authentication.cryptogram;
  321. }
  322. return this._sdk.authorize(authentication.transaction_id, request);
  323. }
  324. })
  325. .then(
  326. authorization => {
  327. // Payment Authorization failed - Display status message
  328. if (authorization.status) {
  329. // "Additional authentication" required
  330. if (authorization.messages[0].code == 640416) {
  331. request = this.getAuthenticateConsumerRequest(paymentMethodId);
  332. // Perform Strong Consumer Authentication (SCA)
  333. if (request) {
  334. // Use token returned by a 3rd party wallet such as Google Pay for strong consumer authentication
  335. if (token) {
  336. request.payment_details.token = token;
  337. }
  338. var cfg = this.getIFrameConfig('consumer-authentication');
  339. if (cfg.container) {
  340. this._sdk.clearContainer(cfg.container);
  341. }
  342. this._sdk.authenticate(authorization.transaction_id, request, cfg)
  343. .then(
  344. authentication => {
  345. // Consumer Authentication failed
  346. if (authentication.status) {
  347. // Consumer Authentication failure
  348. if (authentication.status == 511) {
  349. this.displayAuthenticationFailure(authentication);
  350. }
  351. // API request failed - Display status message
  352. else {
  353. this.displayStatusMessage(authentication);
  354. }
  355. return Promise.reject(null);
  356. }
  357. else {
  358. request = this.getAuthorizePaymentRequest(paymentMethodId);
  359. if (request.hasOwnProperty('payment_details') ) {
  360. // Use token returned by a 3rd party wallet such as Apple Pay or Google Pay for payment authorization
  361. if (token) {
  362. request.payment_details.token = token;
  363. }
  364. request.payment_details.cryptogram = authentication.cryptogram;
  365. }
  366. else {
  367. // Use token returned by a 3rd party wallet such as Apple Pay or Google Pay for payment authorization
  368. if (token) {
  369. request.token = token;
  370. }
  371. request.cryptogram = authentication.cryptogram;
  372. }
  373. this._sdk.authorize(authentication.transaction_id, request)
  374. .then(
  375. reauth => {
  376. // Payment Authorization failed - Display status message
  377. if (reauth.status) {
  378. this.displayStatusMessage(reauth);
  379. }
  380. // Payment Authorization completed - Display success message
  381. else {
  382. this.displayPaymentConfirmation(reauth);
  383. }
  384. }
  385. )
  386. .catch(reason => {
  387. // Low level error - Display error message
  388. if (reason) {
  389. console.error(`Internal error: ${reason} ${reason.stack}`);
  390. }
  391. if (this._container) {
  392. this._container.style.visibility = 'hidden';
  393. }
  394. });
  395. }
  396. }
  397. )
  398. .catch(reason => {
  399. // Low level error - Display error message
  400. if (reason) {
  401. console.error(`Internal error: ${reason} ${reason.stack}`);
  402. }
  403. if (this._container) {
  404. this._container.style.visibility = 'hidden';
  405. }
  406. });
  407. }
  408. else {
  409. this.displayStatusMessage(authorization);
  410. }
  411. }
  412. else {
  413. this.displayStatusMessage(authorization);
  414. }
  415. }
  416. // Payment Authorization completed - Display success message
  417. else {
  418. this.displayPaymentConfirmation(authorization);
  419. }
  420. })
  421. .catch(reason => {
  422. // Low level error - Display error message
  423. if (reason) {
  424. console.error(`Internal error: ${reason} ${reason.stack}`);
  425. }
  426. if (this._container) {
  427. this._container.style.visibility = 'hidden';
  428. }
  429. });
  430. }
  431. /* ========== COMMON METHODS END ========== */
  432. }
  433. /* ========== CALLBACK METHODS START ========== */
  434. /**
  435. * Displays the details of a failed API request.
  436. * It is strongly recommended to override this method as the default implementation will simply display an alert with the localized message.
  437. *
  438. * @example <caption>Override displayStatusMessage</caption>
  439. * TranspayrentUIHelper.prototype.displayStatusMessage = function (result) {
  440. * this._sdk.getLocalizedMessage(`API: ${result.api} failed with HTTP Status Code: ${result.status} and error: ${result.messages[0].message} (${result.messages[0].code})`)
  441. * .then(text => {
  442. * if (this._container) {
  443. * this._container.style.visibility = 'hidden';
  444. * }
  445. * alert(text);
  446. * });
  447. * }
  448. *
  449. * @see {@link Transpayrent#getLocalizedMessage}
  450. *
  451. * @param {Status} result The status object with a list of status message(s) returned by the Payment Gateway
  452. */
  453. TranspayrentUIHelper.prototype.displayStatusMessage = function (result) {
  454. this._sdk.getLocalizedMessage(`API: ${result.api} failed with HTTP Status Code: ${result.status} and error: ${result.messages[0].message} (${result.messages[0].code})`)
  455. .then(text => {
  456. if (this._container) {
  457. this._container.style.visibility = 'hidden';
  458. }
  459. alert(text);
  460. });
  461. }
  462. /**
  463. * Displays the details of a failure during Strong Consumer Authentication (SCA).
  464. * It is strongly recommended to override this method as the default implementation will simply display an alert with the localized message.
  465. *
  466. * @example <caption>Override displayAuthenticationFailure</caption>
  467. * TranspayrentUIHelper.prototype.displayAuthenticationFailure = function (result) {
  468. * this._sdk.getLocalizedStatusMessage(result.status_code)
  469. * .then(text => {
  470. * if (this._container) {
  471. * this._container.style.visibility = 'hidden';
  472. * }
  473. * var message = document.createElement('h1');
  474. * message.className = 'failure';
  475. * message.innerHTML = '<img id="loader" src="/failure.png" width="30" height="30" alt="- completed -" />';
  476. * message.innerHTML += ` ${text} (${result.status_code})`;
  477. * document.body.appendChild(message);
  478. * });
  479. * }
  480. *
  481. * @see {@link Transpayrent#getLocalizedStatusMessage}
  482. *
  483. * @param {AuthenticationFailureResult} result The result of a failed authentication of the consumer for a payment transaction using Strong Consumer Authentication (SCA)
  484. */
  485. TranspayrentUIHelper.prototype.displayAuthenticationFailure = function (result) {
  486. this._sdk.getLocalizedStatusMessage(result.status_code)
  487. .then(text => {
  488. if (this._container) {
  489. this._container.style.visibility = 'hidden';
  490. }
  491. alert(`${text} (${result.status_code})`);
  492. });
  493. }
  494. /**
  495. * Displays the details of the successfully completed payment transaction.
  496. * It is strongly recommended to override this method as the default implementation will simply display an alert with the localized message.
  497. *
  498. * @example <caption>Override displayPaymentConfirmation</caption>
  499. * TranspayrentUIHelper.prototype.displayPaymentConfirmation = function (result) {
  500. * this._sdk.getLocalizedMessage(`Payment transaction: ${authorization.transaction_id} successfully authorized`)
  501. * .then(text => {
  502. * if (this._container) {
  503. * this._container.style.visibility = 'hidden';
  504. * }
  505. * var message = document.createElement('h1');
  506. * message.className = 'success';
  507. * message.innerHTML = '<img id="loader" src="/success.png" width="30" height="30" alt="- completed -" />';
  508. * message.innerHTML += ` ${text}`;
  509. * document.body.appendChild(message);
  510. * });
  511. * }
  512. *
  513. * @see {@link Transpayrent#getLocalizedMessage}
  514. *
  515. * @param {AuthorizePaymentResponse} authorization The details for the successful authorization of a payment transaction
  516. */
  517. TranspayrentUIHelper.prototype.displayPaymentConfirmation = function (authorization) {
  518. this._sdk.getLocalizedMessage(`Payment transaction: ${authorization.transaction_id} successfully authorized`)
  519. .then(text => {
  520. if (this._container) {
  521. this._container.style.visibility = 'hidden';
  522. }
  523. alert(text);
  524. });
  525. }
  526. /**
  527. * Returns a representation of the consumer's payment transaction.
  528. *
  529. * @see {@link Transpayrent#createTransaction}
  530. *
  531. * @param {PAYMENT_METHOD_ID} paymentMethodId The payment method selected by the consumer
  532. * @returns {CreatePaymentTransactionRequest} A representation of the consumer's payment transaction.
  533. */
  534. TranspayrentUIHelper.prototype.getCreateTransactionRequest = function (paymentMethodId) {
  535. console.error(`Method: getCreateTransactionRequest not overriden`);
  536. return null;
  537. }
  538. /**
  539. * Returns a representation of the initialization details provided by the consumer the selected payment method
  540. *
  541. * @see {@link Transpayrent#initialize}
  542. *
  543. * @param {PAYMENT_METHOD_ID} paymentMethodId The payment method selected by the consumer
  544. * @returns {InitializationDetails} A representation of the initialization details provided by the consumer the selected payment method
  545. */
  546. TranspayrentUIHelper.prototype.getInitializePaymentRequest = function (paymentMethodId) {
  547. console.error(`Method: getInitializePaymentRequest not overriden`);
  548. return null;
  549. }
  550. /**
  551. * Returns a representation of the entered payment details required for strong authentication of a payment transaction using 3D Secure or equivalent.
  552. *
  553. * @see {@link Transpayrent#authenticate}
  554. *
  555. * @param {PAYMENT_METHOD_ID} paymentMethodId The payment method selected by the consumer
  556. * @returns {AuthenticateConsumerRequest} A representation of the entered payment details required for strong authentication of a payment transaction using 3D Secure or equivalent.
  557. * Please note that the `browser` property will be constructed automatically.
  558. */
  559. TranspayrentUIHelper.prototype.getAuthenticateConsumerRequest = function (paymentMethodId) {
  560. console.error(`Method: getAuthenticateConsumerRequest not overriden`);
  561. return null;
  562. }
  563. /**
  564. * Returns a representation of a payment details (card details, wallet details, voucher details etc.), which will be used to authorize the payment for the payment transaction
  565. *
  566. * @see {@link Transpayrent#authorize}
  567. *
  568. * @param {PAYMENT_METHOD_ID} paymentMethodId The payment method selected by the consumer
  569. * @returns {PaymentDetails} A representation of a payment details (card details, wallet details, voucher details etc.), which will be used to authorize the payment for the payment transaction
  570. */
  571. TranspayrentUIHelper.prototype.getAuthorizePaymentRequest = function (paymentMethodId) {
  572. console.error(`Method: getAuthorizePaymentRequest not overriden`);
  573. return null;
  574. }
  575. /**
  576. * Returns the payment details for the payment card which will be securely stored in Transpayrent's Secure Valut and added to the consumer's wallet
  577. *
  578. * @see {@link Transpayrent#save}
  579. *
  580. * @param {PAYMENT_METHOD_ID} paymentMethodId The payment method selected by the consumer
  581. * @returns {SaveConsumerValuableRequest} The payment details for the payment card which will be securely stored in Transpayrent's Secure Valut and added to the consumer's wallet
  582. */
  583. TranspayrentUIHelper.prototype.getSaveRequest = function (paymentMethodId) {
  584. console.error(`Method: getSaveRequest not overriden`);
  585. return null;
  586. }
  587. /**
  588. * Returns the configuration for the iframe element which is used when initializing the payment through a 3rd party wallet such as MobilePay
  589. * or displaying the authentication challenge during a 3D Secure flow.
  590. * The default implementation will apply a CSS class with the name of the action: `consumer-authentication` or `payment-initialization` to the constructed iframe.
  591. *
  592. * @see {@link Transpayrent#displayChallenge}
  593. * @see {@link Transpayrent#displayPaymentInitialization}
  594. *
  595. * @param {String} action The action for which the iframe will be constructed, may be one of:
  596. * - `consumer-authentication`
  597. * - `payment-initialization`
  598. * @returns {IFrameConfig} The configuration for the iframe element which is used when initializing the payment through a 3rd party wallet such as MobilePay or displaying the authentication challenge
  599. */
  600. TranspayrentUIHelper.prototype.getIFrameConfig = function (action) {
  601. const loader = this._loader;
  602. var config = { container : this._container,
  603. css: action,
  604. callback : function (event, iframe) {
  605. switch (event) {
  606. case 'payment-initialization-initiated':
  607. case 'authentication-challenge-initiated':
  608. if (loader) {
  609. loader.style.visibility = 'hidden';
  610. }
  611. break;
  612. case 'payment-initialization-completed':
  613. case 'authentication-challenge-completed':
  614. if (loader) {
  615. loader.style.visibility = 'inherit';
  616. }
  617. break;
  618. default:
  619. console.warn(`Unsupported event: ${event}`);
  620. break;
  621. }
  622. } };
  623. return config;
  624. }
  625. /* ========== CALLBACK METHODS END ========== */