From aeb092371f48bf8d14060ee2c53c939a683c3509 Mon Sep 17 00:00:00 2001 From: Ronan LE MEILLAT Date: Sun, 23 Jul 2023 17:49:46 +0200 Subject: [PATCH] v0.9.12 add a static Up2Pay. --- README.md | 4 +++- src/up2pay.ts | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 95a82f6..7f44d21 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Where `form` contains an object similar to the one below. { "url": "https://preprod-tpeweb.up2pay.com/cgi/MYchoix_pagepaiement.cgi", "method": "POST", - "form": "", + "form": "
RonanL.18 route de Notre-Dame-de-la-Gorge74170Les Contamines-Montjoie250
" />12" />", "elements": [ { "name": "PBX_SITE", @@ -111,6 +111,8 @@ const form = await payment.form(); ``` Note: It is better to use the `form` string instead of the `elements` array because the values are computed in a given order. This way you are certain that there will be no problem. +If you want to populate dynamically with `form.elements` a form you can use `Up2Pay.populateForm(parentForm,form.elements)` + ### Check the returned transaction Always use the `payboxRepondreA` to check the transaction. This is a url directly called by Up2Pay from server to server that returns the result of the transaction. diff --git a/src/up2pay.ts b/src/up2pay.ts index d4d784b..4fe052d 100644 --- a/src/up2pay.ts +++ b/src/up2pay.ts @@ -293,6 +293,21 @@ export class Up2Pay implements Document { //return he.encode(szRet, { useNamedReferences: true }) return szRet } + + /** + * + * @param parentFormElement the HTMLFormElement wich contains all the new inputs (must exist) + * @param payboxFormElements the elements to adds (probably form.elements) + */ + static populateForm(parentFormElement: HTMLFormElement, payboxFormElements: FormElement[]): void { + payboxFormElements.map((e) => { + const _inputElement: HTMLInputElement = document.createElement('input') as HTMLInputElement; + _inputElement.type = "hidden"; + _inputElement.name = e.name; + _inputElement.value = e.value; + parentFormElement.appendChild(_inputElement) + }) + } } const returnVars = <{ [index: string]: string }>{