Skip to content

Commit a6496d2

Browse files
authored
Merge pull request AdobeDocs#328 from oshmyheliuk/CEXT-4313
CEXT-4313: Create a new extension to allow filtering payment methods
2 parents 70147c6 + 4621428 commit a6496d2

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

src/pages/starter-kit/checkout/use-cases.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,77 @@ You can also enable webhook signature generation by following the [webhooks sign
138138
139139
Refer to [`actions/validate-payment.js`](https://github.com/adobe/commerce-checkout-starter-kit/blob/main/actions/validate-payment/index.js) for an example of how to receive the request and validate the payment according to the payment gateway needs.
140140

141+
## Payment methods: Filter out payment method
142+
143+
In some cases, you may want to filter out a payment method based on the cart details or the customer's information. For example, you may want to disable a payment method based on customer group or product attributes in the cart.
144+
145+
You can use the `plugin.magento.out_of_process_payment_methods.api.payment_method_filter.get_list` webhook to filter out a payment method. This webhook is triggered every time the list of available payment methods is requested, allowing you to filter out the payment methods based on the cart details or customer information.
146+
147+
The following example demonstrates how to add a webhook to the `plugin.magento.out_of_process_payment_methods.api.payment_method_filter.get_list` method:
148+
149+
```xml
150+
<method name="plugin.magento.out_of_process_payment_methods.api.payment_method_filter.get_list" type="after">
151+
<hooks>
152+
<batch name="check_product_stock">
153+
<hook name="check_product_stock" url="https://<yourappbuilder>.runtime.adobe.io/api/v1/web/commerce-checkout-starter-kit/filter-payment" method="POST" timeout="20000" softTimeout="0">
154+
<fields>
155+
<field name="payload" />
156+
</fields>
157+
</hook>
158+
</batch>
159+
</hooks>
160+
</method>
161+
```
162+
163+
Payload example:
164+
165+
```json
166+
{
167+
"payload": {
168+
"cart": {
169+
"entity_id": "1",
170+
"store_id": 1,
171+
"converted_at": null,
172+
"is_active": "1",
173+
...
174+
"items": [
175+
{
176+
"item_id": "4",
177+
"quote_id": "1",
178+
"product_id": "10",
179+
"store_id": 1,
180+
"weight": "124.000000",
181+
"qty": 2,
182+
"price": "600.0000",
183+
"base_price": "600.0000",
184+
...
185+
"product": {
186+
"entity_id": "10",
187+
...
188+
"attributes": {
189+
"manufacturer": "Two",
190+
"color": "Yellow",
191+
"country_origin": "France",
192+
...
193+
}
194+
},
195+
},
196+
...
197+
],
198+
},
199+
"customer": {
200+
"entity_id": "1",
201+
"website_id": "1",
202+
"email": "test@example.com",
203+
"group_id": "1",
204+
...
205+
}
206+
}
207+
}
208+
```
209+
210+
You can find examples of how to filter out payment methods using customer data or product attributes in your App Builder application in [`actions/filter-payment.js`](https://github.com/adobe/commerce-checkout-starter-kit/blob/main/actions/filter-payment/index.js).
211+
141212
## Shipping methods
142213

143214
You can add shipping methods to the checkout process by using [webhooks](../../webhooks/index.md).

0 commit comments

Comments
 (0)