我想将我的 Mollie .NET 支付客户端(参见https://github.com/Viincenttt/MollieApi)从 v1 升级到 v2。
我已经安装了库,但无法创建付款请求或检查其状态,因为我找不到示例代码中描述的Amount
方法和类型:Currency
IPaymentClient paymentClient = new PaymentClient("{yourApiKey}");
PaymentRequest paymentRequest = new PaymentRequest() {
Amount = new Amount(Currency.EUR, "100.00"),
Description = "Test payment of the example project",
RedirectUrl = "http://google.com"
};
Github 存储库不是很活跃,开发人员没有回应那里的问题,所以希望这里有人能够帮助我。
我已经检查了所有课程以及 Github 的示例项目。我尝试使用“F12 / Go to definition”在示例项目中查找相关方法/类型的定义,但失败了。所以我现在被困住了。
这是我的 Intellisense 向我展示的内容:
我究竟做错了什么?
更新 1
通过导入正确的库并按照@Nkosi 的建议检查迁移文档,我更进一步。
我现在有下面的代码,但得到错误:
BC37058 'Await' 只能在 Async 方法中使用。考虑使用“异步”修饰符标记此方法并将其返回类型更改为“任务”。
上
Dim paymentResponse As PaymentResponse = Await paymentClient.CreatePaymentAsync(paymentRequest)
C# 示例代码是
PaymentResponse paymentResponse = await paymentClient.CreatePaymentAsync(paymentRequest);
但我不知道这如何转化为 VB.net,并且在线代码转换器也没有提供任何解决方案。
Dim paymentClient As Mollie.Api.Client.PaymentClient
If ConfigurationManager.AppSettings("IsDevelopment") = "true" Then
paymentClient = New Client.PaymentClient(ConfigurationManager.AppSettings(String.Format("mollie_api_testkey_{0}", _lang)))
Else
paymentClient = New Client.PaymentClient(ConfigurationManager.AppSettings(String.Format("mollie_api_livekey_{0}", _lang)))
End If
Select Case hfPaymentMethod.Value
Case "ideal"
Dim paymentRequest As New Mollie.Api.Models.Payment.Request.IdealPaymentRequest
paymentRequest.Amount = New Amount(Currency.EUR, "100.00") ' decimalAmount.ToString
paymentRequest.Description = "Subscription. id:" + _vendorId.ToString + " t:" + _objtype.ToString
paymentRequest.RedirectUrl = ConfigurationManager.AppSettings(String.Format("WebAddress_{0}", _lang)) + "paymentvalidate?oid=" + newOrderId.ToString +
"&transactiontype=subscription&id=" + _vendorId.ToString + "&t=" + _objtype.ToString + "&lvl=" + ddlSubscription.SelectedValue.ToString
Dim paymentResponse As PaymentResponse = Await paymentClient.CreatePaymentAsync(paymentRequest)
orderTA.UpdateOrderTransactionId(paymentResponse.Id, newOrderId)
Response.Redirect(paymentResponse.Links.Checkout.ToString)
Case "paypal"
Dim paymentRequest As New Mollie.Api.Models.Payment.Request.PayPalPaymentRequest
Case "creditcard"
Dim paymentRequest As New Mollie.Api.Models.Payment.Request.CreditCardPaymentRequest
End Select
更新 3
好的,再进一步,现在正在触发呼叫。但是,我现在收到此错误:
提供的令牌不是 oauth 令牌。
在线的
Dim paymentStatus As PaymentResponse = Await paymentClient.GetPaymentAsync(transactionId, True)`
请注意,在 Update 2 的代码块中(在我的 upgrade.aspx 页面上)我存储了 transactionid,例如tr_VneHN4axS9
在我的 Orders 表中:
orderTA.UpdateOrderTransactionId(paymentResponse.Id, newOrderId)
这newOrderId
也附加在支付请求的 redirectURL 中,因此我可以在paymentvalidate
页面上再次检索正确的订单:
paymentRequest.RedirectUrl = ConfigurationManager.AppSettings(String.Format("WebAddress_{0}", _lang)) + "paymentvalidate?oid=" + newOrderId.ToString +
"&transactiontype=subscription&id=" + _vendorId.ToString + "&t=" + _objtype.ToString + "&lvl=" + ddlSubscription.SelectedValue.ToString`
在我的 paymentvalidate.aspx 页面上,我从 URL 中获取 orderid,然后使用它来检索 transactionId:
Dim orderId As Integer = ReturnQueryString(Request.Params("oid"), 0)
Dim transactionId As String = orderTA.GetDataOrderById(orderId)(0).transactionId
但是当我尝试像这样检索该事务的状态时:
Dim paymentStatus As PaymentResponse = Await paymentClient.GetPaymentAsync(transactionId, True)`
我得到错误
提供的令牌不是 oauth 令牌。
为什么会抛出这个错误?