Accessing custom Payment Provider Settings in a Surface Controller
Hi,
Is there any way to access any custom Payment Provider settings in a Surface Controller?
For example, in a Cart or Checkout controller we would like to access some of the custom PaymentProviderSetting property values such as 'Sandbox Mode' etc.
I can retrieve an instance of the Payment Provider but it's just the generic payment provider object and doesn't have any of our custom properties. We can see the custom properties in the SettingsDefinition dictionary but not actually access their values.
Generally speaking it's possible to do, but I would say things could be done a slightly different way.
Rather than using a surface controller to bypass the payment provider, you could instead use the payment providers callback URL as a way to communicate via the payment provider.
In most scenarios the callback handler is used to handle webhooks, but in reality, the callback URL of a payment provider can really be thought of as just a generic handler function that can be used for anything, including communication back to the payment provider. So if you communicated to the callback URL, Vendr would already take care of getting the settings and then within the ProcessCallback method you could do whatever you need and you would already be passed the relevant settings for your provider.
I can dig out some code for the approach you are currently taking, but thought I'd highlight the option above as it's all really already in place for you.
Ok, just re-read your question and if it's within the checkout controller you are wanting access to these, maybe it is best to just access them direct.
You can use the following code to get your translated settings as a dictionary
var paymentMethod = _vendr.Services.PaymentMethodService.GetPaymentMethod(order.PaymentInfo.PaymentMethodId.Value);
var settings = _vendr.Services.TranslationService.TranslateValues(paymentMethod.PaymentProviderSettings, order.LanguageIsoCode);
Where _vendr is a VendrContext instance.
Unfortunately the code we have for converting the settings dictionary into a strongly typed model is all internal to the payment provider so you'll currently have to work with the settings as a dictionary or look at calling some internal Vendr code (specifically we have an AsPoco<TModel>() extension method which does this, but as I say, this is currently internal.
If you are just looking for the sandbox mode setting though, maybe this will be enough.
Thanks again for your response. Hopefully a quick question to finish...
I have reworked our code/logic to use the Payment Provider Settings as part of the Payment Provider as normal.
Going through the checkout process now and everything works - except our Callback result does not redirect or transfer to our order complete page, we just land on the callback method url itself.
The ProcessCallback method is being hit correctly and, stepping through the code in the method, everything is correct (and the order saves/finalises as expected). However once the method completes and returns the CallbackResult.Ok result the browser just lands on the callback url itself i.e.
Without knowing fully how your Payment Provider works, I think you might need to use Option 2 from the linked post above to create a continue URL that both processes your callback and redirects you to the continue URL.
Another potential option is the ProcessCallback method can also return a HttpResponseMessage which you could make redirect to a specific location, but I'd probably suggest trying Option 2 documented above first as there are some other steps Vendr performs during these requests.
Accessing custom Payment Provider Settings in a Surface Controller
Hi,
Is there any way to access any custom Payment Provider settings in a Surface Controller?
For example, in a Cart or Checkout controller we would like to access some of the custom PaymentProviderSetting property values such as 'Sandbox Mode' etc.
I can retrieve an instance of the Payment Provider but it's just the generic payment provider object and doesn't have any of our custom properties. We can see the custom properties in the SettingsDefinition dictionary but not actually access their values.
Thanks, Derek
Hi Derek,
Generally speaking it's possible to do, but I would say things could be done a slightly different way.
Rather than using a surface controller to bypass the payment provider, you could instead use the payment providers callback URL as a way to communicate via the payment provider.
In most scenarios the callback handler is used to handle webhooks, but in reality, the callback URL of a payment provider can really be thought of as just a generic handler function that can be used for anything, including communication back to the payment provider. So if you communicated to the callback URL, Vendr would already take care of getting the settings and then within the ProcessCallback method you could do whatever you need and you would already be passed the relevant settings for your provider.
I can dig out some code for the approach you are currently taking, but thought I'd highlight the option above as it's all really already in place for you.
Hope this helps
Matt
Hi Matt,
Thanks for responding, anything you could do with examples (of either approach) would be much appreciated.
Thanks, Derek
Ok, just re-read your question and if it's within the checkout controller you are wanting access to these, maybe it is best to just access them direct.
You can use the following code to get your translated settings as a dictionary
Where
_vendr
is aVendrContext
instance.Unfortunately the code we have for converting the settings dictionary into a strongly typed model is all internal to the payment provider so you'll currently have to work with the settings as a dictionary or look at calling some internal Vendr code (specifically we have an
AsPoco<TModel>()
extension method which does this, but as I say, this is currently internal.If you are just looking for the
sandbox
mode setting though, maybe this will be enough.Hi Matt,
Thanks again for your response. Hopefully a quick question to finish...
I have reworked our code/logic to use the Payment Provider Settings as part of the Payment Provider as normal.
Going through the checkout process now and everything works - except our Callback result does not redirect or transfer to our order complete page, we just land on the callback method url itself.
The ProcessCallback method is being hit correctly and, stepping through the code in the method, everything is correct (and the order saves/finalises as expected). However once the method completes and returns the CallbackResult.Ok result the browser just lands on the callback url itself i.e.
/umbraco/vendr/payment/callback/PaymentProviderAlias/Guid/
In the CMS we have set the 'continue url' on the Payment Methods as "/checkout/complete/" - should we not be redirected there automatically?
Thanks, Derek
Hi Derek,
I think the answer here might be covered by this answer I gave on another thread https://our.umbraco.com/packages/website-utilities/vendr/vendr-support/108325-using-the-callback-url-and-other-urls-in-a-paymentprovider#comment-336471
Without knowing fully how your Payment Provider works, I think you might need to use Option 2 from the linked post above to create a continue URL that both processes your callback and redirects you to the continue URL.
Another potential option is the
ProcessCallback
method can also return aHttpResponseMessage
which you could make redirect to a specific location, but I'd probably suggest trying Option 2 documented above first as there are some other steps Vendr performs during these requests.Hope this helps
Matt
is working on a reply...