Mollie v2 .NET 库创建和检查支付请求的状态

Mollie v2 .NET library creating and checking status of a payment request

我想将我的 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" 在示例项目中找到相关 methods/types 的定义,但是失败了。所以我现在卡住了。

这是我的 Intellisense 显示的内容:

我做错了什么?

更新 1

我进一步导入了正确的库并检查了@Nkosi 推荐的 migration docs

我现在有下面的代码,但出现错误:

BC37058 'Await' can only be used within an Async method. Consider marking this method with the 'Async' modifier and changing its return type to 'Task'.

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

好的,更进一步,现在正在触发调用。但是,我现在收到此错误:

The provided token isn't an oauth token.

在线

Dim paymentStatus As PaymentResponse = Await paymentClient.GetPaymentAsync(transactionId, True)`

请注意更新 2 中我的代码块(在我的 upgrade.aspx 页面上)我存储了事务 ID,例如tr_VneHN4axS9 在我的订单 table 此处:

orderTA.UpdateOrderTransactionId(paymentResponse.Id, newOrderId)

newOrderId 也附加在付款请求的重定向 URL 中,因此我可以在 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)`

我收到错误

The provided token isn't an oauth token.

为什么会抛出这个错误?

问题列表中有关于该错误的内容:https://github.com/Viincenttt/MollieApi/issues/61

因此,如果:(!string.IsNullOrWhiteSpace(paymentRequest.ProfileId) || paymentRequest.Testmode.HasValue || paymentRequest.ApplicationFee != null) 它将 运行 this.ValidateApiKeyIsOauthAccesstoken();