Skip to content

Commit ad489bc

Browse files
authored
Update 4. Demonstrate ability to customize shipping and pa yment methods.md
1 parent 4f2da97 commit ad489bc

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

8. Customizing the Checkout Process/4. Demonstrate ability to customize shipping and pa yment methods.md

+76
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,79 @@ But this doesn't seem to be used.
216216
- void() - `can_void`, `void` command
217217
- acceptPayment() - `can_accept_payment`, `accept_payment` command
218218
- denyPayment() - `can_deny_payment`, `deny_payment` command
219+
220+
221+
Two more special commands: `vault_authorize`, `vault_sale`, `vault_capture`
222+
223+
224+
braintree - BraintreeFacade = Model\Method\Adapter:
225+
- BraintreeValueHandlerPool: default, can_void, can_cancel
226+
- BraintreeCommandPool: authorize, sale, capture, settlement, vault_authorize, vault_sale, vault_capture, void, refund, cancel, deny_payment
227+
- BraintreeValidatorPool: country
228+
229+
braintree_cc_vault - BraintreeCreditCardVaultFacade = Magento\Vault\Model\Method\Vault:
230+
- `vaultProvider` = BraintreeFacade. very important, all methods proxy to this
231+
- BraintreeVaultPaymentValueHandlerPool: default
232+
233+
Magento\Vault\Model\Method\Vault:
234+
- pure class, no parent, interface \Magento\Vault\Model\VaultPaymentInterface
235+
- proxies almost all methods: is`*`, can`*`, validate
236+
- not implemented, throws error: initialize(), order(), refund(), cancel(), void(), acceptPayment(), denyPayment()
237+
- assignData:
238+
* event `payment_method_assign_data_vault`
239+
* event `payment_method_assign_data_vault_{$code}`
240+
* original payment `method.assignData`
241+
- authorize:
242+
* attach token extension attribute:
243+
+ `customer_id` from payment.additional_information
244+
+ `publish_hash` from payment.additional_information
245+
+ order payment.extension attributes[`vault_payment_token`] =
246+
\Magento\Vault\Api\PaymentTokenManagementInterface::getByPublicHash(`publish_hash`, `customer_id`)
247+
+ select from `vault_payment_token` where publish_hash = ? and customer_id = ?/NULL
248+
* commandManagerPool[`method.code`].executeBycode(`vault_authorize`)
249+
- capture:
250+
* ONLY for `order`=`sale` payment action? Authorization transaction must not exist
251+
* attach token extension attribute
252+
* commandManagerPool[`method.code`].executeBycode(`vault_sale`)
253+
254+
### Payment Tips
255+
256+
Sometimes capture should do one of 3 things - sale, capture or vault_capture.
257+
Braintree makes CaptureStrategyCommand command that checks payment and
258+
calls needed capture type command.
259+
260+
Virtual types can extend and augment each other pretty heavily, for example
261+
BraintreePayPalSaleCommand is based on BraintreePayPalAuthorizeCommand
262+
and changes only request builder.
263+
264+
To make Vault work, after you receive normal payment, you save token by customer. Braintree
265+
does this in AuthorizationCommand handler chain in one of handlers. Token
266+
is simply read from response and put to order payment.extension_attributes[`vault_payment_token`].
267+
268+
Vault on frontend:
269+
- in checkout config provider, finds all payment methods implementing Vault interface and returns codes for JS
270+
- in checkout payment methods, adds `vault` payment method group
271+
- get component providers \Magento\Vault\Model\Ui\TokenUiComponentProviderInterface - return params for JS component
272+
* Braintree registers component in DI \Magento\Vault\Model\Ui\TokensConfigProvider
273+
- tokens = select from `vault_payment_token` where customer_id = ? and is_visible = 1 and is_active = 1 and expires_at > time
274+
- for each token, run component providers[method.code].getComponentForToken
275+
- window.checkoutConfig.payment.vault = [
276+
`{$code}_{$i}` = componentConfig,
277+
braintree_cc_vault_0 = {...},
278+
braintree_cc_vault_1 = {...},
279+
]
280+
281+
282+
## What types of payment methods exist?
283+
- offline
284+
- online
285+
- gateway
286+
- vault - works over gateway, but executes different commands for authorize and capture. Always work in terms of previously saved token for customer.
287+
288+
## What are the different payment flows?
289+
- isInitializationNeeded = true
290+
291+
Manually do the job in `initialize` and return custom order status and state.
292+
293+
- authorize, capture
294+
- order = authorize + capture

0 commit comments

Comments
 (0)