I want to upgrade my Mollie .NET payment client (see https://github.com/Viincenttt/MollieApi) from v1 to v2.
I've installed the library, but am unable to create a payment request or check its status, as I can't find the Amount
method and Currency
type as described in the sample code:
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"
};
The Github repository is not very active, the developer is not responding to issues there, so hopefully someone here is able to help me.
I've checked out all classes and also the sample project from Github. I tried finding the definition of the relevant methods/types in the sample project, using "F12 / Go to definition", but that fails. So I'm stuck now.
Here's what my Intellisense shows me:
What am I doing wrong?
UPDATE 1
I'm a few steps further by importing the right libraries and checking the migration docs as recommended by @Nkosi.
I now have the code below, but get error:
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'.
on
Dim paymentResponse As PaymentResponse = Await paymentClient.CreatePaymentAsync(paymentRequest)
The C# sample code is
PaymentResponse paymentResponse = await paymentClient.CreatePaymentAsync(paymentRequest);
but I don't know how that translates to VB.net and online code converters provide no solution either.
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
UPDATE 3
Ok, another step further, the call is now being triggered. However, I now get this error:
The provided token isn't an oauth token.
On line
Dim paymentStatus As PaymentResponse = Await paymentClient.GetPaymentAsync(transactionId, True)`
Notice in my codeblock in Update 2 (which is on my upgrade.aspx page) that I store the transactionid, e.g. tr_VneHN4axS9
in my Orders table here:
orderTA.UpdateOrderTransactionId(paymentResponse.Id, newOrderId)
That newOrderId
is also appended in the redirectURL of the payment request so I can retrieve the correct order again on the paymentvalidate
page:
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`
On my paymentvalidate.aspx page I get the orderid from the URL and then use that to retrieve the transactionId:
Dim orderId As Integer = ReturnQueryString(Request.Params("oid"), 0)
Dim transactionId As String = orderTA.GetDataOrderById(orderId)(0).transactionId
But when I then try to retrieve the status of that transaction like so:
Dim paymentStatus As PaymentResponse = Await paymentClient.GetPaymentAsync(transactionId, True)`
I get the error
The provided token isn't an oauth token.
Why is this error being thrown?
There is something on that error in the issues list: https://github.com/Viincenttt/MollieApi/issues/61
So if: (!string.IsNullOrWhiteSpace(paymentRequest.ProfileId) || paymentRequest.Testmode.HasValue || paymentRequest.ApplicationFee != null)
it will run this.ValidateApiKeyIsOauthAccesstoken();
.