mih*_*hai 5 payment payment-gateway worldpay typescript angular
我正在尝试将 Worldpay 集成到 angular2 应用程序中。
我正在使用自己的表单(own-form)方法,需要将其脚本包含在页面中:
<script src="https://cdn.worldpay.com/v1/worldpay.js"></script>
为某些输入添加特定属性:data-worldpay并将Worldpay.js逻辑附加到表单中...
我设法完成以下步骤:
1. 在您的页面中包含 Worldpay.js
2. 创建具有相关属性的付款表单
我怎样才能继续进行下一步......我陷入了这个问题:
5. 将 Worldpay.js 附加到您的表单:
<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>
Run Code Online (Sandbox Code Playgroud)
为什么?
angular2 从模板中删除所有标签<script。
假设有一个解决方法,可以在ngAfterViewInit()方法中的页面中注入一些脚本(就像我在第一步中所做的那样)
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);
}
Run Code Online (Sandbox Code Playgroud)
其中this.worldPayScriptElement是模板中 div 的 ViewChild:<div #worldPayScriptElement hidden></div>
但是,根据他们的处理规则,worldpay 将使用名为CreditCardToken 的字段替换我表单中的敏感数据
最后,在 Worldpay.formBuilder() 中,所有敏感卡数据都会从表单中删除,并替换为令牌,然后才将表单提交回您的服务器。 来源: https: //developer.worldpay.com/jsonapi/docs/own-form
如何继续整合这个...无法理解。
如果他们有一个 API 根据请求返回 CreditCardTokenGET/POST那就完美了,但从文档中我还没有找到正确的方法......
我将非常感谢任何建议。
我已经决定考虑另一种方法:)
我已经使用 Worldpay API 来获取令牌。
API 网址:https://api.worldpay.com/v1/tokens
端点等待POST以下形式的请求:
'{
"reusable": true/false,
"paymentMethod": {
"name": "name",
"expiryMonth": 2,
"expiryYear": 2015,
"issueNumber": 1,
"startMonth": 2,
"startYear": 2013,
"cardNumber": "4444 3333 2222 1111",
"type": "Card",
"cvc": "123"
},
"clientKey": "T_C_client_key"
}'
Run Code Online (Sandbox Code Playgroud)
其中Header应包含以下选项: "Content-type: application/json"
这样,就不再需要包含worldpay.js在页面中了。
此外,不再需要在付款表单中包含 worldpay 特定属性(例如data-worldpay="")
只需调用 API,等待响应,其形式如下:
{
"token": "UUID of token",
"reusable": true/false,
"paymentMethod": {
"type" : "ObfuscatedCard",
"name": "name",
"expiryMonth": 2,
"expiryYear": 2015,
"issueNumber": 1,
"startMonth": 2,
"startYear": 2013,
"cardType": "VISA_CREDIT",
"maskedCardNumber": "xxxx xxxx xxxx 1111",
"cardSchemeType": "consumer",
"cardSchemeName": "VISA CREDIT",
"cardProductTypeDescNonContactless": "Visa Credit Personal",
"cardProductTypeDescContactless": "CL Visa Credit Pers",
"cardIssuer": "LLOYDS BANK PLC",
"countryCode": "GBR",
"cardClass": "credit",
"prepaid": "false"
}
}
Run Code Online (Sandbox Code Playgroud)
根据回复,您已准备好使用response.token以继续下一步:付款。
您应该确保发送特定的 WorldPay 属性(CreditCardToken、已注册)
我如何在 angular2 中调用 worldpay API?
public getWorldpayToken(request: any): Observable<any>{
let worldPayApiUrl = `https://api.worldpay.com/v1/tokens`;
let body = JSON.stringify(request);
let headers = new Headers({ 'Content-Type':'application/json;charset=UTF-8'});
let options = new RequestOptions({ headers: headers });
return this.http.post(worldPayApiUrl, body, options)
.map(response => response.json())
.catch(this.handleError);
}
Run Code Online (Sandbox Code Playgroud)
文档: https: //developer.worldpay.com/jsonapi/api#tokens
对于任何其他细节,请随时发表评论/询问:)
| 归档时间: |
|
| 查看次数: |
3225 次 |
| 最近记录: |