Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Bitcoin Coinbase API for PHP - Example

Bitcoin is an innovative payment network and a new kind of money. Bitcoin is the world's most widely used alternative currency with a total market cap of approximately $10 billion. The bitcoin network is made up of thousands of computers run by individuals all over the world.

Bitcoin Coinbase API for PHP - Example


Here i am going to present a small example to send money with Coinbase API. You can create a new payment button with Coinbase api. Let see step by step how it will work.

Step 1: Create a payment.php file


<?php
require __DIR__ . '/vendor/autoload.php';

use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;
use Coinbase\Wallet\Value\Money;
use Coinbase\Wallet\Resource\Checkout;
use Coinbase\Wallet\Resource\Order;
    
$apiKey = 'API KEY';
$apiSecret = 'API SECRET';

$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);

$amount = 0.1;
$orderId = "YOUR ORDER ID";

$params = array(
    'name'          => 'Site order ID: '.$orderId,
    'amount'        => new Money($amount, 'USD'),
    'metadata'      => array('order_id' => $orderId),
    'auto_redirect' => true
);

$checkout = new Checkout($params);
$client->createCheckout($checkout);
$code = $checkout->getEmbedCode();

$redirect_url = "https://www.coinbase.com/checkouts/$code";
?>

Step 2: Create a notification.php file


<?php 
require __DIR__ . '/vendor/autoload.php';

use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;
use Coinbase\Wallet\Value\Money;
use Coinbase\Wallet\Resource\Checkout;
use Coinbase\Wallet\Resource\Order;

$apiKey = 'API KEY';
$apiSecret = 'API SECRET';
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);

$raw_body = file_get_contents('php://input');
$signature = $_SERVER['HTTP_CB_SIGNATURE'];
$authenticity = $client->verifyCallback($raw_body, $signature); // boolean
if($authenticity){
 $order = json_decode($raw_body, true);
    mail("YOUR EMAIL ID","Coinbase Patment Notifications",print_r($order, true));
}
?>

Step 3: Create a success.php file


<?php
$order = $_GET['order'];
var_dump($order);
?>

Note: You need to set these all files url in your coinbase merchant account


You Did not Sign in Correctly or Your Account is Temporarily Disabled Magento 2

When you try to login to your Magento 2 admin, you got this message You did not sign in correctly or your account is temporarily disabled . You don’t know that you are not using username or password. In this guide, I will show to how to resolve this sign in problem “You did not sign in correctly or your account is temporarily disabled”.

Your Account is Temporarily Disabled Magento2

The fix was to make sure there is 1 alpha character and 1 numeric character in the admin password. This should be labelled a bug if the password is not validated during install with magento setup:install

Solution: Unlock admin account


try command in case the account is locked
php bin/magento admin:user:unlock 

Or go to Magento 2 root folder and type
php bin/magento admin:user:unlock 

Your Account is Temporarily Disabled Magento2

Related product disappear after adding to Cart [Fixed]

I have noticed that after adding a product to cart, it disappears in list of related products. It's a default Magento feature that after adding an item to cart, it disappears under the related products of a specific product. If you want to still show that specific product even if already added it to cart You need to rewrite the block Mage_Catalog_Block_Product_List_Related and from the method _prepareData comment following line

Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter($this->_itemCollection, 
    Mage::getSingleton('checkout/session')->getQuoteId()
);

It is a good practice to not change any core file. Better to over write this file in your local folder. Create directory like

/app/code/local/Mage/Catalog/Block/Product/List and copy Related.php file in this directory.


Get the Hash ( # ) value from url using jQuery or Javascript

Get the value after a hash in the URL of the current page.

var hash = window.location.hash.substr(1);
alert(hash);


Generating Random Names With PHP

This is a short tutorial on how to generate random names with PHP. With PHP you can automatically generate random name using this script.

In this example, we have two PHP arrays. One contains a list of common names. The other contains a list of common surnames. Using the function mt_rand.

PHP


Demo

<?php
$names = array(
    'Hardik',
    'Shivam',
    'Nirmal',
    'Kaushik',
    'Pradip',
    'Rixit',
    'Neel',
    'Samantha',
);
 
//PHP array containing surnames.
$surnames = array(
    'Patel',
    'Thompson',
    'Anderson',
    'Johnson',
    'Tremblay',
    'Peltier',
    'Cunningham',
    'Simpson',
    'Mercado',
    'Sellers'
);
 
//Generate a random name.
$random_name = $names[mt_rand(0, sizeof($names) - 1)];
 
//Generate a random surname.
$random_surname = $surnames[mt_rand(0, sizeof($surnames) - 1)];
 
//Combine them together and print out the result.
echo $random_name . ' ' . $random_surname;
?>



 

Copyright @ 2017 HKblog.