3

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;
}
2
  • Why you use the deprecated method instead of payment gateway?
    – Sohel Rana
    Jul 4, 2019 at 7:04
  • i read now that its deprecated. i want the order to process within magento and not get redirected out. how can i do that? Jul 4, 2019 at 7:15

1 Answer 1

1

There are some links you can refer

https://www.mageplaza.com/devdocs/magento-2-create-order-programmatically.html

How to create order programmatically in Magento 2?

3
  • Thank you very much, il try them out @Mohit Rane Jul 4, 2019 at 7:15
  • have you solved your problem ?
    – Mohit Rane
    Jul 4, 2019 at 7:47
  • no sorry, it still doesnt place the order and redirect me the success page @Mohit Rane Jul 4, 2019 at 8:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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