I am trying to integrate Worldpay in an angular2 app.
I am using own form (own-form) approach where it is necessary to include their script in page:
<script src="https://cdn.worldpay.com/v1/worldpay.js"></script>
Add specific attibutes for some inputs: data-worldpay
and attach the Worldpay.js logic to the form...
I managed to make the steps:
1. Include Worldpay.js in your page
2. Create a payment form with the relevant attributes
How can I continue to make next steps... I am stuck on that problem:
5. Attach Worldpay.js to your form:
<script type="text/javascript">
var form = document.getElementById('paymentForm');
Worldpay.useOwnForm({
'clientKey': 'your-test-client-key',
'form': form,
'reusable': false,
'callback': function(status, response) {
document.getElementById('paymentErrors').innerHTML = '';
if (response.error) {
Worldpay.handleError(form, document.getElementById('paymentErrors'), response.error);
} else {
var token = response.token;
Worldpay.formBuilder(form, 'input', 'hidden', 'token', token);
form.submit();
}
}
});
</script>
Why?
angular2 removes all tags <script
from templates.
Supposing with a workaround it would be possible to inject some scripts in page in ngAfterViewInit()
method (like i did for 1st step)
ngAfterViewInit(): void {
let s = document.createElement("script");
s.type = "text/javascript";
s.src = "https://cdn.worldpay.com/v1/worldpay.js";
this.worldPayScriptElement.nativeElement.appendChild(s);
}
where this.worldPayScriptElement
is a ViewChild of the div from template: <div #worldPayScriptElement hidden></div>
But, As result of their processing rules, worldpay will replace sensitive data from my form with a field called CreditCardToken
From source: Finally, in Worldpay.formBuilder() all sensitive card data is removed from the form, replaced with the token and only then is the form submitted back to your server. source: https://developer.worldpay.com/jsonapi/docs/own-form
How to continue integrating this ... Cannot understand.
If they would have an API returning the CreditCardToken based on a GET/POST
request it would be perfect, but from documentation I didn't found yet the right method for that...
I will really appreciate any kind of suggestions.