6

Considering a custom Payment Method class extending \Magento\Payment\Model\Method\AbstractMethod: Would somebody kindly explain what do the methods below do?

initialize($paymentAction, $stateObject)
validate()

order(\Magento\Payment\Model\InfoInterface $payment, $amount)
authorize(\Magento\Payment\Model\InfoInterface $payment, $amount)

capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
refund(\Magento\Payment\Model\InfoInterface $payment, $amount)
cancel(\Magento\Payment\Model\InfoInterface $payment)
void(\Magento\Payment\Model\InfoInterface $payment)

Thanks!

0

2 Answers 2

9
  1. initialize: Instantiate state and set it to state object. Method that will be executed instead of authorize or capture if flag isInitializeNeeded set to true.

  2. validate: Validate payment method information that means validate payment method is allowed for billing country or not.

  3. order: Check order availability.
  4. authorize: Payment process authorize only. After authorize, you need to capture amount manually.
  5. capture: Capture payment amount. When this method called, system automatically capture amount.
  6. refund: Refund specified amount for payment.
  7. cancel: Cancel payment.
  8. void: void specified amount for payment. Some payment method don't allow refund within 24hrs. So in that case you need to call void for refund that amount.

[Update]

Where actually during checkout process does authorize and capture is being called?

Solution:

Open Magento/Sales/Model/Order/Payment.php Check following method.

  1. place
  2. processAction
5
  • Thanks for your answer. Just 2 questions: 1) What does 'void specified amount' mean? 2) Where does 'capture' actually being called? Jan 27, 2017 at 14:09
  • Check updated answer.
    – Sohel Rana
    Jan 27, 2017 at 14:14
  • 'void specified amount' mean -> you can specified how much you need to void.
    – Sohel Rana
    Jan 27, 2017 at 14:15
  • Where actually during checkout process does authorize and capture is being called? For my module only validate is called! Jan 27, 2017 at 14:21
  • Check updated answer.
    – Sohel Rana
    Jan 27, 2017 at 14:35
5

It's as deprecated approach to extend \Magento\Payment\Model\Method\AbstractMethod, instead, you should use Magento payment gateway.

You can find the step-by-step guide how to implement payment method on Magento 2 dev docs based on Magento payment gateway.

Also, Magento has sale(authorize & capture) payment action - it's similar to authorize, but allows process the capturing action for an authorized transaction. This post describes how to implement sale payment action - https://community.magento.com/t5/Magento-DevBlog/The-Magento-Sale-Payment-Operation/ba-p/67251.

1
  • Thank you for the answer. I'll take a look into it. I've up-voted your answer. Jan 27, 2017 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.