Skip to content
Log in

Accounts Payment Methods Controller - Liquid Controller Reference

On this page

Description

The Accounts Payment Methods controller serves the signed-in customer’s saved payment methods. A customer must be signed in.

Property Value
Controller Accounts::PaymentMethodsController
Liquid Template Path controllers/accounts/payment_methods/
Namespace Accounts

Actions

Action HTTP Method Route Result
index GET /account/payment_methods Renders the account page
new GET /account/payment_methods/new Renders the account page
create POST /account/payment_methods Saves the method with the payment provider and responds with JSON
update PATCH, PUT /account/payment_methods/:id Updates the nickname or makes it the default, then redirects back
destroy DELETE /account/payment_methods/:id Removes the saved method, then redirects back

On the pages it renders, current_request.params.section is payment_methods, or payment_methods_new on new. Use it in the account page template to show the right section.

create makes the new method the default when is_default is true, or when it is the customer’s only saved method for the store. It responds with {"redirect_url": "/account/payment_methods"} on success, and with an error_message and status 422 on failure.

Example

Create a theme template with the key controllers/accounts/payment_methods/index to send a customer with no saved methods straight to the add form:

```liquid

{% before %} {% if current_customer.payment_methods.size == 0 %} {% assign new_method_path = current_request.store_path | append: “/account/payment_methods/new” %} {% redirect to: new_method_path %} {% endif %} {% endbefore %} ```

See how Liquid controllers work for the phases and the tags you can use in them.

Was this article helpful?

Was this article helpful?