Implement payment method filtering¶
You can use payment method filtering to decide, whether selected payment method can be used and displayed in checkout process. To allow this filtering, you need to create a custom payment method type and register new voter.
Create custom payment method type¶
There are different ways you can extend your Payment module implementation. One of them is to create a custom payment method type.
The following example shows, how to create New Payment Method Type
.
Define custom payment method type¶
First, register the new payment method type as a service:
1 2 3 4 5 6 7 8 9 10 |
|
In the arguments
list provide a name of the payment method type, the way you want it to appear on the list of available payment method types, in the following example: New Payment Method Type
.
Now new custom payment method type should be visible in Commerce -> Payment methods.
Create voter for new payment method type¶
Next, create a NewPaymentMethodTypeVoter.php
file with the voter definition for your new payment method type:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
Created voter decides, if selected payment method type can be used and displayed in checkout process.
Register new voter¶
Register new voter as a service:
1 2 3 |
|
Clear cache¶
Now, clear the cache by running the following command:
1 |
|
Then, you can create a payment of the new type.