Magento 2.1 – Payment Method Configuration

magento-2.1magento2paymentpayment-methods

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!

Best Answer

  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
Related Topic