ive built a custom payment method followed a few tutorials to get the output. but im now stuck at the point where 'Place Order' won't work.
I am using Magento 2. If i could get some guidance on where to call my payment method to display the success page that would be great.
I currently have this setup in my model.
<?php
namespace Jacks\Custompayment\Model;
/**
* Class Custompayment
*
* @method \Magento\Quote\Api\Data\PaymentMethodExtensionInterface
getExtensionAttributes()
*
*/
class Custompayment extends \Magento\Payment\Model\Method\cc
{
const PAYMENT_METHOD_CUSTOMPAYMENT_CODE = 'custompayment';
/**
* Payment method code
*
* @var string
*/
protected $_code = self::PAYMENT_METHOD_CUSTOMPAYMENT_CODE;
/**
* @var string
*/
protected $_formBlockType = \Emipro\Custompayment\Block\Form\Custompayment::class;
/**
* @var string
*/
protected $_infoBlockType = \Emipro\Custompayment\Block\Info\Custompayment::class;
protected $_canAuthorize= true;
/**
* @return string
*/
public function getPayableTo()
{
return $this->getConfigData('payable_to');
}
/**
* @return string
*/
public function getUsername()
{
return $this->getConfigData('businessID');
}
/**
* @return string
*/
public function getPassword()
{
return $this->getConfigData('password');
}
public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount)
{
if (!$this->canAuthorize()) {
throw new \Magento\Framework\Exception\LocalizedException(__('The authorize action is not available.'));
}
return $this;
}
public function savePaymentInformationAndPlaceOrder($cartId,\Magento\Quote\Api\Data\PaymentInterface $paymentMethod,\Magento\Quote\Api\Data\AddressInterface $billingAddress = null)
{
$this->savePaymentInformation($cartId, $paymentMethod, $billingAddress);
try
{
$orderId = $this->cartManagement->placeOrder($cartId);
}
catch (\Exception $e)
{
throw new CouldNotSaveException(
__('An error occurred on the server. Please try to place the order again.'),
$e
);
}
return $orderId;
}