本文介绍了在MVC WorldPay的整合问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想实现WorldPay的付款方式在我的MVC项目,并努力使测试付款,但它表明我这个错误
- 你已经完成或取消您的付款。
- 您已经饼干禁用。完成付款,通过在浏览器更改隐私设置使
饼干。然后
返回到商家的网站,然后重新提交您的付款。 - 您在WorldPay的会话已超时。请返回
商家的网站,并重新提交您的付款。
我试图 $ B $
代码b
<形式的行动=https://secure-test.worldpay.com/wcc/purchase方法=后>
<输入名称=地址1型=隐藏值=唐宁街10号/>
<输入名称=量类型=隐藏值=100.00/>
<输入名称=cartId类型=隐藏值=DAW/>
<输入名称=OP-DPChoose-VISA ^ SSL类型=隐藏值=DAW/>
<输入名称=cardNoInput类型=隐藏值=4444333322221111/>
<输入名称=国家类型=隐藏值=GB/>
<输入名称=货币类型=隐藏值=英镑/>
<输入名字=电子邮件类型=隐藏值[email protected]/>
<输入名称=instId类型=隐藏值=eca6aba9-16b2-4ad0-8019-1212bbb2f152/>
<输入名称=名称类型=隐藏值=总理/>
<输入名称=邮编类型=隐藏值=SW1A 2AA/>
<输入名称=电话类型=隐藏值=020 7925 0918/>
<输入名称=TESTMODE类型=隐藏值=100/>
<输入名称=镇类型=隐藏值=伦敦/>
<输入名称=cardCVV类型=隐藏值=1234/>
<输入名称=cardExp.month类型=隐藏值=1/>
<输入名称=cardExp.year类型=隐藏值=2017年/>
< DIV CLASS =表单组>
<按钮类=BTN BTN-成功BTN-LG类型=提交> WorldPay的测试Checkout的LT; /按钮>
< / DIV>
< /表及GT;
解决方案
通过WorldPay的试试这个测试下订单。
<形式的行动=/完成ID =paymentForm方法=后>
<跨度ID =paymentErrors>< / SPAN>
< DIV CLASS =表格行>
<标签>关于名称卡< /标签>
<输入数据WorldPay的=名称NAME =名类型=文本/>
< / DIV>
< DIV CLASS =表格行>
<标签>卡号和LT; /标签>
<输入数据WorldPay的=数字大小=20型=文本/>
< / DIV>
< DIV CLASS =表格行>
<标签>&CVC LT; /标签>
<输入数据WorldPay的=CVC大小=4类型=文本/>
< / DIV>
< DIV CLASS =表格行>
<标签>到期(MM / YYYY)LT; /标签>
<输入数据WorldPay的=EXP-月大小=2类型=文本/>
<标签> /< /标签>
<输入数据WorldPay的=EXP年的大小=4类型=文本/>
< / DIV>
<输入类型=提交值=订单/>
< /表及GT;
然后在您的视图文件
添加这个脚本
<脚本SRC =https://cdn.worldpay.com/v1/worldpay.js>< / SCRIPT>
<脚本类型=文/ JavaScript的>
变种形式=的document.getElementById('paymentForm');
Worldpay.useOwnForm({
'clientKey':'Your_Client_Key',
形式:形式,
'可重复使用的:虚假,
'回调:功能(状态,响应){
的document.getElementById('paymentErrors')的innerHTML ='';
如果(response.error){
Worldpay.handleError(表单,文档.getElementById('paymentErrors'),response.error);
}其他{
VAR令牌= response.token;
Worldpay.formBuilder(形式,输入,隐藏,令牌,令牌);
的console.log(令牌);
$阿贾克斯({
URL:/首页/支付/,
数据: {令牌:令牌}
成功:功能(数据){
},
数据类型:HTML,
型:POST,
缓存:假的,
错误:函数(){
//错误信息
}
});
form.submit();
}
}
});
< / SCRIPT>
现在在你的控制器
添加此下单码
公众的ActionResult支付(字符串标记)
{
变种RESTClient实现=新WorldpayRestClient(https://api.worldpay.com/v1,Your_Service_Key );
变种orderRequest =新OrderRequest()
{
记号=记号,
额= 500,
CURRENCYCODE = CurrencyCode.GBP.ToString()
NAME =测试名称,
orderDescription =订单描述,
customerOrderCode =订货代码
};
变种地址=新地址()
{
地址1 =123家路,
地址2 =A村,
城市=伦敦,
COUNTRYCODE = CountryCode.GB,
POSTALCODE =EC1 1AA
};
orderRequest.billingAddress =地址;
试
{
OrderResponse orderResponse = restClient.GetOrderService()创建(orderRequest);
Console.WriteLine(订单代码:+ orderResponse.orderCode);
}
赶上(WorldpayException E)
{
Console.WriteLine(错误代码:+ e.apiError.customCode);
Console.WriteLine(错误描述:+ e.apiError.description);
Console.WriteLine(错误信息:+ e.apiError.message);
}
返回JSON(NULL,JsonRequestBehavior.AllowGet);
}
I am trying to implement worldpay payment method in my MVC project and trying to make a test payment but it shows me this error
- You have completed or cancelled your payment.
- You have cookies disabled. To complete your payment, enablecookies by changing the privacy settings in your browser. Thenreturn to the merchant's site and resubmit your payment.
- Your session at WorldPay has timed out. Please return to themerchant's site and resubmit your payment.
Code that i am trying
<form action="https://secure-test.worldpay.com/wcc/purchase" method="post">
<input name="address1" type="hidden" value="10 Downing Street" />
<input name="amount" type="hidden" value="100.00" />
<input name="cartId" type="hidden" value="DAW" />
<input name="op-DPChoose-VISA^SSL" type="hidden" value="DAW" />
<input name="cardNoInput" type="hidden" value="4444333322221111" />
<input name="country" type="hidden" value="GB" />
<input name="currency" type="hidden" value="GBP" />
<input name="email" type="hidden" value="[email protected]" />
<input name="instId" type="hidden" value="eca6aba9-16b2-4ad0-8019-1212bbb2f152" />
<input name="name" type="hidden" value="Prime Minister" />
<input name="postcode" type="hidden" value="SW1A 2AA" />
<input name="tel" type="hidden" value="020 7925 0918" />
<input name="testMode" type="hidden" value="100" />
<input name="town" type="hidden" value="London" />
<input name="cardCVV" type="hidden" value="1234" />
<input name="cardExp.month" type="hidden" value="1" />
<input name="cardExp.year" type="hidden" value="2017" />
<div class="form-group">
<button class="btn btn-success btn-lg" type="submit">WorldPay Test Checkout</button>
</div>
</form>
解决方案
Try this for test Order placement through WorldPay
<form action="/complete" id="paymentForm" method="post">
<span id="paymentErrors"></span>
<div class="form-row">
<label>Name on Card</label>
<input data-worldpay="name" name="name" type="text" />
</div>
<div class="form-row">
<label>Card Number</label>
<input data-worldpay="number" size="20" type="text" />
</div>
<div class="form-row">
<label>CVC</label>
<input data-worldpay="cvc" size="4" type="text" />
</div>
<div class="form-row">
<label>Expiration (MM/YYYY)</label>
<input data-worldpay="exp-month" size="2" type="text" />
<label> / </label>
<input data-worldpay="exp-year" size="4" type="text" />
</div>
<input type="submit" value="Place Order" />
</form>
Then add this script in your view file
<script src="https://cdn.worldpay.com/v1/worldpay.js"></script>
<script type="text/javascript">
var form = document.getElementById('paymentForm');
Worldpay.useOwnForm({
'clientKey': 'Your_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);
console.log(token);
$.ajax({
url: "/Home/payment/",
data: { token: token },
success: function (data) {
},
dataType: "html",
type: "POST",
cache: false,
error: function () {
//Error Message
}
});
form.submit();
}
}
});
</script>
Now add this Order Placement code in your controller
public ActionResult payment(string token)
{
var restClient = new WorldpayRestClient("https://api.worldpay.com/v1", "Your_Service_Key");
var orderRequest = new OrderRequest()
{
token = token,
amount = 500,
currencyCode = CurrencyCode.GBP.ToString(),
name = "test name",
orderDescription = "Order description",
customerOrderCode = "Order code"
};
var address = new Address()
{
address1 = "123 House Road",
address2 = "A village",
city = "London",
countryCode = CountryCode.GB,
postalCode = "EC1 1AA"
};
orderRequest.billingAddress = address;
try
{
OrderResponse orderResponse = restClient.GetOrderService().Create(orderRequest);
Console.WriteLine("Order code: " + orderResponse.orderCode);
}
catch (WorldpayException e)
{
Console.WriteLine("Error code:" + e.apiError.customCode);
Console.WriteLine("Error description: " + e.apiError.description);
Console.WriteLine("Error message: " + e.apiError.message);
}
return Json(null, JsonRequestBehavior.AllowGet);
}
这篇关于在MVC WorldPay的整合问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!