Credit card payment on delivery - magento-1.7

In magento checkout page i want Credit card payment on delivery like the cash on delivery
Is anyone implemented this Credit card payment on delivery please help me
Also please provide links for reffering
Thanks in advance

Just code, yes it's possible do that.
basically you just need a model like these:
The basic structure to payment module is (i'll show example with basic payment with 1 additional information field:
Module
------->Block
------------->Form
------------------->Pay.php
------------->Info
------------------->Pay.php
------->etc
------------->config.xml
------------->system.xml
------->Model
------------->Paymentmethodmodel.php
Important things about this module:
Yourpaymentmodule_Block_Form_Pay
This block make the frontend view. The code:
<?php
class YourPaymentModule_Block_Form_Pay extends Mage_Payment_Block_Form
{
protected function _construct(){
parent::_construct();
$this->setTemplate('yourpaymentmodule/form/pay.phtml');
}
}
The other one is Yourpaymentmodule_Block_Info_Pay, this one make the view from Admin Order Details.
<?php
class YourPaymentModule_Block_Info_Pay extends Mage_Payment_Block_Info
{
protected function _construct(){
parent::_construct();
$this->setTemplate('yourpaymentmodule/form/pay.phtml');
}
protected function _prepareSpecificInformation($transport = null)
{
if (null !== $this->_paymentSpecificInformation) {
return $this->_paymentSpecificInformation;
}
$info = $this->getInfo();
$transport = new Varien_Object();
$transport = parent::_prepareSpecificInformation($transport);
$transport->addData(array(
Mage::helper('payment')->__('Additional Information') => $info->getAdditional(),
));
return $transport;
}
}
And finally on your model:
<?php
class PPaymentModuleName_Model_PaymentModuleName extends Mage_Payment_Model_Method_Abstract
{
protected $_code = 'custompaymentmodule';
protected $_formBlockType = 'custompaymentmodule/form_pay';
protected $_infoBlockType = 'custompaymentmodule/info_pay';
protected $_canUseInternal = true;
protected $_canOrder = true;
public function assignData($data)
{
if (!($data instanceof Varien_Object)) {
$data = new Varien_Object($data);
}
$info = $this->getInfoInstance();
$info->setAdditionalINformation($data->getAdditionalINformation());
return $this;
}
public function canUseForCountry($country)
{
return true;
}
public function canUseForCurrency($currencyCode){
return true;
}
}
?>
On your phtml files you make the design, just simple field or something.
Other important thing is in your etc/modules/CustomPaymentModule.xml:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<CustomPaymentModule>
<active>true</active>
<codePool>community</codePool>
<depends>
<Mage_Payment />
</depends>
</CustomPaymentModule>
</modules>
</config>
And this is it.

Related

Magento2 - how do I call a function in another class?

I'm creating an observer and I'm trying to connect it to saving a new product. If the product is new I'm trying to run a code, if not - skip.
I made an observer before save in creating a new product and after that I want to run the same code as shared catalog -> shared catalogs -> default -> set pricing and structure -> and just save without changing anything.
This is my code:
NewProductReindexer/etc/adminhtml/events.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="catalog_product_save_before">
<observer name="Company_module_event_after_observer" instance="Company\NewProductReindexer\Observer\NewProductObserver"/>
</event>
Observer/NewProductObserver.php
class NewProductObserver implements ObserverInterface
{
public function __construct()
{
}
public function execute(Observer $observer)
{
$isProductNew = $product->isObjectNew();
if($isProductNew == true){
//new product
}else{
relax();
}
}
}
The two ways to call you a block class method in the custom module class
using constructor dependency like that
public function __construct(Namespace\ModuleName\Helper\Data $helper)
{
$this->helper = $helper;
}
public function MyFunction()
{ $this->helper->HelperDemo();
}
using method dependency public function execute(Namespace\ModuleName\Helper\Data $helper) { $helper->HelperDemo(); }
For more detail visit the below link https://devdocs.magento.com/guides/v2.3/extension-dev-guide/depend-inj.html

Class 'REST_Controller' not found in my Codeigniter code how to solve it.?

I am New in REST API.i want to create a REST API With codeigniter.But i am face error thats i can't solve my self.
Controller:-
defined('BASEPATH') OR exit('No direct script access allowed');
require(APPPATH.'/libraries/REST_Controller.php');
require APPPATH . '/libraries/Format.php';
class Api extends REST_Controller{
public function __construct()
{
parent::__construct();
$this->load->model('book_model');
}
//API - Fetch All books
function books_get(){
$result = $this->book_model->getallbooks();
if($result){
$this->response($result, 200);
}
else{
$this->response("No record found", 404);
}
}
Model code:-
class Book_model extends CI_Model {
public function __construct(){
parent::__construct();
}
//API call - get all books record
public function getallbooks(){
$this->db->select('id, name, price, author, category, language, ISBN, publish_date');
$this->db->from('tbl_books');
$this->db->order_by("id", "desc");
$query = $this->db->get();
if($query->num_rows() > 0){
return $query->result_array();
}else{
return 0;
}
}
My Error While Test in Post Man:-

How to render product list in my custom widget

I am creating my custom module for magento 2.3 and I've faced an issue with widget.
I have created my widget type and when I include it to homepage I have to see product list of products I've selected to render.
I want to use .../magento/vendor/magento/module-catalog/view/frontend/templates/product/list.phtml as a template
The problem is that Widget class has to Extend Magento\Framework\View\Element\Template class, and to render ProductList I have to extend Magento\Catalog\Block\Product\ListProduct.
Maybe someone could give me a piece of advice how to solve this problem.
Here is a part of my code
file my-vendor/my-module/Block/Widget/MyWidget.php
class PromotedWidget extends Template implements BlockInterface
{
public function __construct(
Context $context,
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
array $data = []
)
{
$this->productCollectionFactory = $productCollectionFactory;
parent::__construct($context, $data);
}
public function getLoadedProductCollection()
{
$collection = $this->productCollectionFactory->create();
$collection->addAttributeToSelect('*');
$collection->addAttributeToFilter('necessary_attribute', ['necessary_attribute' => 'attr_value']);
return $collection;
}
public function toHtml()
{
$this->setTemplate('Magento_Catalog::product/list.phtml');
return parent::_toHtml();
}
}
I think it is not good practice to extend Magento\Catalog\Block\Product\ListProduct class. If you want to load custom product collection and want it to work it same as product listing page, then I suggest you to create a plugin for Magento\CatalogSearch\Model\Search\IndexBuilder class in your custom widget as follows:
Namespace\Modulename\etc\di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\CatalogSearch\Model\Search\IndexBuilder">
<plugin name="Namespace_Modulename::custom_collection" type="Namespace\Modulename\Plugin\CatalogSearch\Model\Search\IndexBuilder" />
</type>
</config>
Namespace\Modulename\Plugin\CatalogSearch\Model\Search\IndexBuilder.php
<?php
namespace Namespace\Modulename\Plugin\CatalogSearch\Model\Search;
use Magento\Framework\Search\RequestInterface;
class IndexBuilder {
protected $_request;
protected $_categoryHelper;
public function __construct(
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
\Magento\Catalog\Helper\Category $categoryHelper,
\Magento\Framework\App\Request\Http $request
) {
$this->_productCollectionFactory = $productCollectionFactory;
$this->_categoryHelper = $categoryHelper;
$this->_request = $request;
}
public function aroundBuild($subject, callable $proceed, RequestInterface $request) {
$select = $proceed($request);
$collection = $this->_productCollectionFactory->create();
$collection->addAttributeToSelect('*');
$collection->addAttributeToFilter('necessary_attribute', ['necessary_attribute' => 'attr_value']);
$getProductAllIds = $collection->getAllIds();
$productUniqueIds = array_unique($getProductAllIds);
$select->where("search_index.entity_id IN ('" . join("','", $productUniqueIds) . "')");
return $select;
}
}
In addition, you can refer this link for more details.

Laravel redirect to post method

To stay basic I would like to create a bookmark app
I have a simple bookmarklet
javascript:location.href='http://zas.dev/add?url='+encodeURIComponent(location.href)
I created a rest controller
<?php
use zas\Repositories\DbLinkRepository;
class LinksController extends BaseController {
protected $link;
function __construct(DbLinkRepository $link) {
$this->link=$link;
// ...
//$this->beforeFilter('auth.basic', array('except' => array('index', 'show', 'store')));
// ...
}
public function index()
{
//return Redirect::to('home');
}
public function create()
{
}
public function store()
{
return 'hello';
//$this->link->addLink(Input::get('url'));
//return Redirect::to(Input::get('url'));
}
public function show($id)
{
//$url = $this->link->getUrl($id);
//return Redirect::to($url);
}
public function edit($id)
{
}
public function update($id){
}
public function destroy($id){
}
}
in the routes.php, I created a ressource
Route::resource('links','LinksController');
and as I want to redirect /add to the store method I added
Route::get('/add',function(){
return Redirect::action('LinksController#store');
});
but it never display the hello message, in place it redirects me to
http://zas.dev/links
I also tried with
return Redirect::route('links.store');
without much success
thanks for your help
Ok I now get what you are trying to do. This will work:
Route::get('add', 'LinksController#store');
Remove:
Route::resource('links','LinksController');
and remove:
Route::get('/add',function(){
return Redirect::action('LinksController#store');
});
Sorry it took so long!
The problem is that once you Redirect::, you loose all the Input values, so you should manually give them to your controller when you do the redirect, like so :
Redirect::route('links.store', ["url" => Input::get("url")]);
Finally add an $url parameter to your store method to receive the value we give it in the previous method, like this :
public function store($url) {
$this->link->addLink($url);
return Redirect::to($url);
}

CakePHP and Facebook with Security Component turned on

I want the Security Component turned on.
BUT when you load a CakePHP app inside a Facebook tab, FB posts $_REQUEST['signed_request'] to my form - the problem with this is that the Security Component "reacts" to this "post" and gives me validation errors, black-hole, etc.
How do I go around this?
I could not find anything on the documentation to go around this problem.
What I wanted was to somehow run the Security Component "manually" so that it only "reacts" when I actually submit my form and not when Facebook posts the $_REQUEST['signed_request'] to my form.
UPDATE:
<?php
App::uses('CakeEmail', 'Network/Email');
class PagesController extends AppController {
public $helpers = array('Html','Form');
public $components = array('RequestHandler');
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('*');
$this->Security->validatePost = true;
$this->Security->csrfCheck = true;
$this->Security->unlockedFields[] = 'signed_request';
}
public function home() {
$this->loadModel('Memberx');
if($this->request->is('post') && isset($this->request->data['Memberx']['name'])) {
//...save here, etc. ...
}
}
FYI: I get a "black hole" error.
FINAL UPDATE (After #tigrang's answer):
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('*');
$this->set('hasLiked', false);
if(isset($this->request->data['signed_request'])){
$this->set('hasLiked', $this->hasLiked($this->request->data['signed_request']));
}
if(isset($this->request->data['Memberx']['signed_request'])) {
$this->set('hasLiked', $this->hasLiked($this->request->data['Memberx']['signed_request']));
}
/*
To go around Facebook's post $_REQUEST['signed_request'],
we unset the $_REQUEST['signed_request'] and disable the csrfCheck
ONLY after we have set the hasLiked view variable
*/
unset($this->request->data['signed_request']);
if (empty($this->request->data)) {
$this->Security->csrfCheck = false;
}
}
Then, I do something like below in my views:
<?php
if($hasLiked) {
?>
You have liked this page!
<?php
}
?>
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('*');
$this->_validateFbRequest();
}
protected function _valdiateFbRequest() {
if (!isset($this->request->data['signed_request'])) {
// not a valid request from fb
// throw exception or handle however you want
return;
}
$signedRequest = $this->request->data['signed_request'];
unset($this->request->data['signed_request']);
if (empty($this->request->data)) {
$this->Security->csrfCheck = false;
}
// validate the request
}