├── Api ├── Data │ └── TransactionInterface.php └── TransactionsRepositoryInterface.php ├── Block ├── Info.php └── Page │ └── Success.php ├── Controller └── Api │ ├── Index.php │ └── SaveTransaction.php ├── Cron └── TransactionsCheck.php ├── Gateway ├── Http │ ├── Client │ │ └── ClientMock.php │ └── TransferFactory.php ├── Request │ ├── AuthorizationRequest.php │ └── MockDataRequest.php └── Response │ ├── FraudHandler.php │ └── TxnIdHandler.php ├── Helper └── Data.php ├── LICENSE ├── Model ├── Adminhtml │ └── Source │ │ ├── CryptoCurrency.php │ │ └── PaymentAction.php ├── Client │ └── ShapeShiftClientApi.php ├── Config │ └── Allowcurrency.php ├── CurrencyConverter │ ├── CoinMarketCap.php │ └── Request.php ├── ResourceModel │ ├── Transactions.php │ └── Transactions │ │ └── Collection.php ├── Transactions.php ├── TransactionsRepository.php └── Ui │ └── ConfigProvider.php ├── Observer ├── .DS_Store ├── AfterPlaceOrder.php └── DataAssignObserver.php ├── Plugin └── Payment │ └── Model │ └── Method │ └── Adapter.php ├── README.md ├── Setup └── InstallSchema.php ├── composer.json ├── etc ├── adminhtml │ ├── di.xml │ └── system.xml ├── config.xml ├── cron_groups.xml ├── crontab.xml ├── di.xml ├── events.xml ├── frontend │ ├── di.xml │ └── routes.xml └── module.xml ├── registration.php └── view ├── adminhtml └── templates │ └── info │ └── shapeshift.phtml └── frontend ├── layout ├── checkout_index_index.xml └── checkout_onepage_success.xml ├── templates ├── info │ └── shapeshift.phtml └── page │ └── success.phtml └── web ├── js └── view │ └── payment │ ├── method-renderer │ └── shape_shift.js │ └── shape_shift.js └── template └── payment └── form.html /Api/Data/TransactionInterface.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Api\Data; 8 | 9 | /** 10 | * Interface TransactionInterface 11 | * 12 | * @package Firebear\ShapeShift\Api\Data 13 | */ 14 | interface TransactionInterface 15 | { 16 | 17 | const ENTITY_ID = 'id'; 18 | const ORDER_ID = 'order_id'; 19 | const DEPOSIT_ADDRESS = 'deposit_address'; 20 | const AMOUNT_DEPOSIT = 'amount_deposit'; 21 | const STATUS = 'status'; 22 | 23 | /** 24 | * @return mixed 25 | */ 26 | public function getId(); 27 | 28 | /** 29 | * @param $id 30 | * 31 | * @return mixed 32 | */ 33 | public function setId($id); 34 | 35 | /** 36 | * @return mixed 37 | */ 38 | public function getOrderId(); 39 | 40 | /** 41 | * @param $orderId 42 | * 43 | * @return mixed 44 | */ 45 | public function setOrderId($orderId); 46 | 47 | /** 48 | * @return mixed 49 | */ 50 | public function getDepositAddress(); 51 | 52 | /** 53 | * @param $depositAddress 54 | * 55 | * @return mixed 56 | */ 57 | public function setDepositAddress($depositAddress); 58 | 59 | /** 60 | * @return mixed 61 | */ 62 | public function getAmountDeposit(); 63 | 64 | /** 65 | * @param $amountDeposit 66 | * 67 | * @return mixed 68 | */ 69 | public function setAmountDeposit($amountDeposit); 70 | 71 | /** 72 | * @return mixed 73 | */ 74 | public function getStatus(); 75 | 76 | /** 77 | * @param $status 78 | * 79 | * @return mixed 80 | */ 81 | public function setStatus($status); 82 | } 83 | -------------------------------------------------------------------------------- /Api/TransactionsRepositoryInterface.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Api; 8 | 9 | use Firebear\ShapeShift\Api\Data\TransactionInterface; 10 | 11 | interface TransactionsRepositoryInterface 12 | { 13 | /** 14 | * @param \Firebear\ShapeShift\Api\Data\TransactionInterface $transactionModel 15 | * 16 | * @return \Firebear\ShapeShift\Api\Data\TransactionInterface 17 | * @throws \Magento\Framework\Exception\CouldNotSaveException 18 | */ 19 | public function save(TransactionInterface $transactionModel); 20 | 21 | /** 22 | * @param int $id 23 | * 24 | * @return \Firebear\ShapeShift\Api\Data\TransactionInterface 25 | * @throws \Magento\Framework\Exception\NoSuchEntityException 26 | */ 27 | public function get($id); 28 | 29 | /** 30 | * @param \Firebear\ShapeShift\Api\Data\TransactionInterface $transactionModel 31 | * 32 | * @return bool 33 | * @throws \Magento\Framework\Exception\CouldNotDeleteException 34 | */ 35 | public function delete(TransactionInterface $transactionModel); 36 | 37 | /** 38 | * @param int $id 39 | * 40 | * @return bool 41 | * @throws \Magento\Framework\Exception\CouldNotDeleteException 42 | */ 43 | public function deleteById($id); 44 | } 45 | -------------------------------------------------------------------------------- /Block/Info.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Block; 8 | 9 | use Magento\Framework\Phrase; 10 | use Magento\Payment\Block\ConfigurableInfo; 11 | use Magento\Framework\View\Element\Template\Context; 12 | use Magento\Payment\Gateway\ConfigInterface; 13 | use Firebear\ShapeShift\Model\TransactionsRepository; 14 | use Firebear\ShapeShift\Model\ResourceModel\Transactions\Collection; 15 | 16 | class Info extends ConfigurableInfo 17 | { 18 | 19 | private $transactionRepository; 20 | private $transactionCollectionFactory; 21 | 22 | public function __construct( 23 | Context $context, 24 | ConfigInterface $config, 25 | TransactionsRepository $transactionsRepository, 26 | Collection $transactionCollectionFactory, 27 | array $data = [] 28 | ) { 29 | $template = 'Firebear_ShapeShift::info/shapeshift.phtml'; 30 | $this->transactionRepository = $transactionsRepository; 31 | $this->transactionCollectionFactory = $transactionCollectionFactory; 32 | $this->setTemplate($template); 33 | parent::__construct($context, $config, $data); 34 | } 35 | 36 | public function getTemplateData() 37 | { 38 | $transactionModel = $this->transactionRepository->getByOrderId($this->getInfo()->getOrder()->getId()); 39 | $arrayData = [ 40 | 'depositAddress' => $transactionModel->getDepositAddress(), 41 | 'depositAmount' => $transactionModel->getAmountDeposit() 42 | ]; 43 | 44 | return $arrayData; 45 | } 46 | 47 | /** 48 | * Returns label 49 | * 50 | * @param string $field 51 | * 52 | * @return Phrase 53 | */ 54 | protected function getLabel($field) 55 | { 56 | return __($field); 57 | } 58 | 59 | /** 60 | * Returns value view 61 | * 62 | * @param string $field 63 | * @param string $value 64 | * 65 | * @return string | Phrase 66 | */ 67 | protected function getValueView($field, $value) 68 | { 69 | switch ($field) { 70 | case FraudHandler::FRAUD_MSG_LIST: 71 | return implode('; ', $value); 72 | } 73 | 74 | return parent::getValueView($field, $value); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Block/Page/Success.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Block\Page; 8 | 9 | use Firebear\ShapeShift\Model\TransactionsRepository; 10 | 11 | class Success extends \Magento\Framework\View\Element\Template 12 | { 13 | private $checkoutSession; 14 | private $transactionRepository; 15 | private $registry; 16 | 17 | public function __construct( 18 | \Magento\Framework\View\Element\Template\Context $context, 19 | \Magento\Checkout\Model\Session $checkoutSession, 20 | TransactionsRepository $transactionRepository, 21 | \Magento\Framework\Registry $coreRegistry 22 | ) { 23 | $this->checkoutSession = $checkoutSession; 24 | $this->transactionRepository = $transactionRepository; 25 | $this->registry = $coreRegistry; 26 | parent::__construct($context); 27 | } 28 | 29 | public function getTransactionData() 30 | { 31 | $orderId = $this->registry->registry('last_success_order_id'); 32 | $this->registry->unregister('last_success_order_id'); 33 | $transactionModel = $this->transactionRepository->getByOrderId($this->checkoutSession->getLastOrderId()); 34 | return $transactionModel; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Controller/Api/Index.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Controller\Api; 8 | 9 | use Psr\Log\LoggerInterface; 10 | use Firebear\ShapeShift\Model\Client\ShapeShiftClientApiFactory; 11 | use Magento\Framework\Controller\ResultFactory; 12 | 13 | class Index extends \Magento\Framework\App\Action\Action 14 | { 15 | private $configResource; 16 | 17 | /** 18 | * @var \Magento\Quote\Model\QuoteFactory 19 | */ 20 | private $quoteFactory; 21 | 22 | /** 23 | * @var \Magento\Checkout\Model\Session 24 | */ 25 | private $cart; 26 | 27 | /** 28 | * @var \Magento\Framework\App\Config\ScopeConfigInterface 29 | */ 30 | private $scopeConfig; 31 | 32 | private $logger; 33 | private $checkoutSession; 34 | private $shapeShiftClientApi; 35 | private $shapeShiftHelper; 36 | private $currency; 37 | private $storeManager; 38 | private $resultJsonFactory; 39 | private $orderRepository; 40 | 41 | /** 42 | * Index constructor. 43 | * 44 | * @param \Magento\Framework\App\Action\Context $context 45 | * @param \Magento\Framework\App\Config\MutableScopeConfigInterface $config 46 | * @param \Magento\Checkout\Model\Cart $cart 47 | * @param \Magento\Quote\Model\QuoteFactory $quoteFactory 48 | */ 49 | public function __construct( 50 | \Magento\Framework\App\Action\Context $context, 51 | \Magento\Framework\App\Config\MutableScopeConfigInterface $config, 52 | \Magento\Checkout\Model\Cart $cart, 53 | \Magento\Quote\Model\QuoteFactory $quoteFactory, 54 | \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, 55 | \Magento\Checkout\Model\Session $checkoutSession, 56 | ShapeShiftClientApiFactory $shapeShiftClientApi, 57 | \Firebear\ShapeShift\Helper\Data $shapeShiftHelper, 58 | LoggerInterface $logger, 59 | \Magento\Store\Model\StoreManagerInterface $storeManager, 60 | \Magento\Directory\Model\Currency $currency, 61 | \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory, 62 | \Magento\Sales\Model\OrderRepository $orderRepository 63 | ) { 64 | $this->config = $config; 65 | $this->cart = $cart; 66 | $this->quoteFactory = $quoteFactory; 67 | $this->scopeConfig = $scopeConfig; 68 | $this->logger = $logger; 69 | $this->checkoutSession = $checkoutSession; 70 | $this->shapeShiftClientApi = $shapeShiftClientApi; 71 | $this->shapeShiftHelper = $shapeShiftHelper; 72 | $this->currency = $currency; 73 | $this->storeManager = $storeManager; 74 | $this->resultJsonFactory = $resultJsonFactory; 75 | $this->orderRepository = $orderRepository; 76 | parent::__construct($context); 77 | } 78 | 79 | public function execute() 80 | { 81 | $this->logger->info("API START"); 82 | $returnAddress = $this->getRequest()->getParam('returnAddress'); 83 | $depositAddress = $this->shapeShiftHelper->getGeneralConfig('deposit_address'); 84 | $currencyCode = $this->storeManager->getStore()->getCurrentCurrencyCode(); 85 | $outputCrypto = $this->shapeShiftHelper->getGeneralConfig('currency_crypto'); 86 | $amount = $this->shapeShiftHelper->convertCurrency( 87 | $this->cart->getQuote()->getGrandTotal(), 88 | $currencyCode, 89 | $outputCrypto 90 | ); 91 | $this->logger->info("DEPOSIT ADDRESS: " . $depositAddress); 92 | $this->logger->info("RETURN ADDRESS: " . $returnAddress); 93 | $this->logger->info("AMOUNT: " . $amount); 94 | 95 | $this->logger->info("API XCHECK DEFAULT"); 96 | $shapeShift = $this->shapeShiftClientApi->create(); 97 | $this->logger->info("API XCHECK AMOUNT"); 98 | $inputCrypto = $this->getRequest()->getParam('currencyCode'); 99 | $shapeShift->sendFixedAmount($amount, $depositAddress, $returnAddress, $inputCrypto, $outputCrypto); 100 | $result = $this->resultJsonFactory->create(); 101 | if (isset($shapeShift->error['error'])) { 102 | $jsonResponse = $shapeShift->error; 103 | } else { 104 | $jsonResponse = [ 105 | 'amount' => $shapeShift->depoAmount, 106 | 'address' => $shapeShift->depoAddress 107 | ]; 108 | } 109 | 110 | 111 | return $result->setData($jsonResponse); 112 | $this->logger->info("API STOP"); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /Controller/Api/SaveTransaction.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Controller\Api; 8 | 9 | use Magento\Framework\App\Action\Context; 10 | use Firebear\ShapeShift\Model\TransactionsRepository; 11 | use Magento\Framework\Controller\ResultFactory; 12 | 13 | class SaveTransaction extends \Magento\Framework\App\Action\Action 14 | { 15 | private $transactionsRepository; 16 | private $checkoutSession; 17 | private $registry; 18 | 19 | public function __construct( 20 | Context $context, 21 | TransactionsRepository $transactionsRepository, 22 | \Magento\Checkout\Model\Session $checkoutSession, 23 | \Magento\Framework\Registry $coreRegistry 24 | ) { 25 | $this->transactionsRepository = $transactionsRepository; 26 | $this->checkoutSession = $checkoutSession; 27 | parent::__construct($context); 28 | 29 | } 30 | 31 | public function execute() 32 | { 33 | $depoAddress = $this->getRequest()->getParam('depoAddress'); 34 | $depoAmount = $this->getRequest()->getParam('depoAmount'); 35 | $transactionModel = $this->transactionsRepository->create(); 36 | $transactionModel->setOrderId($this->checkoutSession->getLastRealOrder()->getId()); 37 | $transactionModel->setAmountDeposit($depoAmount); 38 | $transactionModel->setDepositAddress($depoAddress); 39 | $transactionModel->setStatus(1); 40 | $this->transactionsRepository->save($transactionModel); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Cron/TransactionsCheck.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Cron; 8 | 9 | use Firebear\ShapeShift\Model\ResourceModel\Transactions\CollectionFactory as TransactionsCollection; 10 | use Firebear\ShapeShift\Model\Client\ShapeShiftClientApiFactory; 11 | use Magento\Sales\Model\OrderRepository; 12 | use Firebear\ShapeShift\Model\TransactionsRepository; 13 | use Firebear\ShapeShift\Helper\Data; 14 | use Psr\Log\LoggerInterface; 15 | use Magento\Sales\Model\Order; 16 | 17 | class TransactionsCheck 18 | { 19 | private $transactionsCollectionFactory; 20 | private $shapeShiftClientApiFactory; 21 | private $transactionsRepository; 22 | private $orderRepository; 23 | private $helper; 24 | private $log; 25 | 26 | public function __construct( 27 | TransactionsCollection $transactionsCollectionFactory, 28 | ShapeShiftClientApiFactory $shapeShiftClientApiFactory, 29 | OrderRepository $orderRepository, 30 | TransactionsRepository $transactionsRepository, 31 | Data $helper, 32 | LoggerInterface $log 33 | ) { 34 | $this->transactionsCollectionFactory = $transactionsCollectionFactory; 35 | $this->shapeShiftClientApiFactory = $shapeShiftClientApiFactory; 36 | $this->orderRepository = $orderRepository; 37 | $this->transactionsRepository = $transactionsRepository; 38 | $this->helper = $helper; 39 | $this->log = $log; 40 | } 41 | 42 | public function execute() 43 | { 44 | $transactionCollection = $this->transactionsCollectionFactory->create(); 45 | $transactions = $transactionCollection->addFieldToFilter('status', 1)->getItems(); 46 | $shapeShiftClientApi = $this->shapeShiftClientApiFactory->create(); 47 | foreach ($transactions as $transaction) { 48 | $status = $shapeShiftClientApi->getStatus($transaction->getDepositAddress()); 49 | $orderModel = $this->orderRepository->get($transaction->getOrderId()); 50 | if ($status == 'complete') { 51 | $orderModel->setState( 52 | $this->helper->getGeneralConfig('status_order_paid'), 53 | true 54 | )->setStatus($this->helper->getGeneralConfig('status_order_paid')); 55 | $this->orderRepository->save($orderModel); 56 | $transactionModel = $this->transactionsRepository->get($transaction->getId()); 57 | $transactionModel->setStatus(2); 58 | $this->transactionsRepository->save($transactionModel); 59 | } 60 | if ($status == 'failed') { 61 | $orderModel->setState( 62 | Order::STATE_CANCELED, 63 | true 64 | )->setStatus(Order::STATE_CANCELED); 65 | $transactionModel = $this->transactionsRepository->get($transaction->getId()); 66 | $this->orderRepository->save($orderModel); 67 | $transactionModel->setStatus(3); 68 | $this->transactionsRepository->save($transactionModel); 69 | } 70 | if ($status == 'no_deposits') { 71 | $orderModel->setState( 72 | Order::STATE_PENDING_PAYMENT, 73 | true 74 | )->setStatus(Order::STATE_PENDING_PAYMENT); 75 | $this->orderRepository->save($orderModel); 76 | } 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /Gateway/Http/Client/ClientMock.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Gateway\Http\Client; 8 | 9 | use Magento\Payment\Gateway\Http\ClientInterface; 10 | use Magento\Payment\Gateway\Http\TransferInterface; 11 | use Magento\Payment\Model\Method\Logger; 12 | 13 | class ClientMock implements ClientInterface 14 | { 15 | const SUCCESS = 1; 16 | const FAILURE = 0; 17 | 18 | /** 19 | * @var array 20 | */ 21 | private $results = [ 22 | self::SUCCESS, 23 | self::FAILURE 24 | ]; 25 | 26 | /** 27 | * @var Logger 28 | */ 29 | private $logger; 30 | 31 | /** 32 | * @param Logger $logger 33 | */ 34 | public function __construct( 35 | Logger $logger 36 | ) { 37 | $this->logger = $logger; 38 | } 39 | 40 | /** 41 | * Places request to gateway. Returns result as ENV array 42 | * 43 | * @param TransferInterface $transferObject 44 | * @return array 45 | */ 46 | public function placeRequest(TransferInterface $transferObject) 47 | { 48 | $response = $this->generateResponseForCode( 49 | $this->getResultCode( 50 | $transferObject 51 | ) 52 | ); 53 | 54 | $this->logger->debug( 55 | [ 56 | 'request' => $transferObject->getBody(), 57 | 'response' => $response 58 | ] 59 | ); 60 | 61 | return $response; 62 | } 63 | 64 | /** 65 | * Generates response 66 | * 67 | * @return array 68 | */ 69 | protected function generateResponseForCode($resultCode) 70 | { 71 | 72 | return array_merge( 73 | [ 74 | 'RESULT_CODE' => $resultCode, 75 | 'TXN_ID' => $this->generateTxnId() 76 | ], 77 | $this->getFieldsBasedOnResponseType($resultCode) 78 | ); 79 | } 80 | 81 | /** 82 | * @return string 83 | */ 84 | protected function generateTxnId() 85 | { 86 | return hash('sha256', random_int(0, 1000)); 87 | } 88 | 89 | /** 90 | * Returns result code 91 | * 92 | * @param TransferInterface $transfer 93 | * @return int 94 | */ 95 | private function getResultCode(TransferInterface $transfer) 96 | { 97 | $headers = $transfer->getHeaders(); 98 | 99 | if (isset($headers['force_result'])) { 100 | return (int)$headers['force_result']; 101 | } 102 | 103 | return $this->results[random_int(0, 1)]; 104 | } 105 | 106 | /** 107 | * Returns response fields for result code 108 | * 109 | * @param int $resultCode 110 | * @return array 111 | */ 112 | private function getFieldsBasedOnResponseType($resultCode) 113 | { 114 | switch ($resultCode) { 115 | case self::FAILURE: 116 | return [ 117 | 'FRAUD_MSG_LIST' => [ 118 | 'Stolen card', 119 | 'Customer location differs' 120 | ] 121 | ]; 122 | } 123 | 124 | return []; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /Gateway/Http/TransferFactory.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Gateway\Http; 8 | 9 | use Magento\Payment\Gateway\Http\TransferBuilder; 10 | use Magento\Payment\Gateway\Http\TransferFactoryInterface; 11 | use Magento\Payment\Gateway\Http\TransferInterface; 12 | use Firebear\ShapeShift\Gateway\Request\MockDataRequest; 13 | 14 | class TransferFactory implements TransferFactoryInterface 15 | { 16 | /** 17 | * @var TransferBuilder 18 | */ 19 | private $transferBuilder; 20 | 21 | /** 22 | * @param TransferBuilder $transferBuilder 23 | */ 24 | public function __construct( 25 | TransferBuilder $transferBuilder 26 | ) { 27 | $this->transferBuilder = $transferBuilder; 28 | } 29 | 30 | /** 31 | * Builds gateway transfer object 32 | * 33 | * @param array $request 34 | * @return TransferInterface 35 | */ 36 | public function create(array $request) 37 | { 38 | return $this->transferBuilder 39 | ->setBody($request) 40 | ->setMethod('POST') 41 | ->setHeaders( 42 | [ 43 | 'force_result' => isset($request[MockDataRequest::FORCE_RESULT]) 44 | ? $request[MockDataRequest::FORCE_RESULT] 45 | : null 46 | ] 47 | ) 48 | ->build(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Gateway/Request/AuthorizationRequest.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Gateway\Request; 8 | 9 | use Magento\Payment\Gateway\ConfigInterface; 10 | use Magento\Payment\Gateway\Data\PaymentDataObjectInterface; 11 | use Magento\Payment\Gateway\Request\BuilderInterface; 12 | 13 | class AuthorizationRequest implements BuilderInterface 14 | { 15 | /** 16 | * @var ConfigInterface 17 | */ 18 | private $config; 19 | 20 | /** 21 | * @param ConfigInterface $config 22 | */ 23 | public function __construct( 24 | ConfigInterface $config 25 | ) { 26 | $this->config = $config; 27 | } 28 | 29 | /** 30 | * Builds ENV request 31 | * 32 | * @param array $buildSubject 33 | * @return array 34 | */ 35 | public function build(array $buildSubject) 36 | { 37 | if (!isset($buildSubject['payment']) 38 | || !$buildSubject['payment'] instanceof PaymentDataObjectInterface 39 | ) { 40 | throw new \InvalidArgumentException('Payment data object should be provided'); 41 | } 42 | 43 | /** @var PaymentDataObjectInterface $payment */ 44 | $payment = $buildSubject['payment']; 45 | $order = $payment->getOrder(); 46 | $address = $order->getShippingAddress(); 47 | 48 | return [ 49 | 'TXN_TYPE' => 'A', 50 | 'INVOICE' => $order->getOrderIncrementId(), 51 | 'AMOUNT' => $order->getGrandTotalAmount(), 52 | 'CURRENCY' => $order->getCurrencyCode(), 53 | 'EMAIL' => $address->getEmail(), 54 | 'MERCHANT_KEY' => $this->config->getValue( 55 | 'merchant_gateway_key', 56 | $order->getStoreId() 57 | ) 58 | ]; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Gateway/Request/MockDataRequest.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Gateway\Request; 8 | 9 | use Magento\Payment\Gateway\Data\PaymentDataObjectInterface; 10 | use Magento\Payment\Gateway\Request\BuilderInterface; 11 | use Firebear\ShapeShift\Gateway\Http\Client\ClientMock; 12 | 13 | class MockDataRequest implements BuilderInterface 14 | { 15 | const FORCE_RESULT = 'FORCE_RESULT'; 16 | 17 | /** 18 | * Builds ENV request 19 | * 20 | * @param array $buildSubject 21 | * @return array 22 | */ 23 | public function build(array $buildSubject) 24 | { 25 | if (!isset($buildSubject['payment']) 26 | || !$buildSubject['payment'] instanceof PaymentDataObjectInterface 27 | ) { 28 | throw new \InvalidArgumentException('Payment data object should be provided'); 29 | } 30 | 31 | /** @var PaymentDataObjectInterface $paymentDO */ 32 | $paymentDO = $buildSubject['payment']; 33 | $payment = $paymentDO->getPayment(); 34 | 35 | $transactionResult = $payment->getAdditionalInformation('transaction_result'); 36 | return [ 37 | self::FORCE_RESULT => $transactionResult === null 38 | ? ClientMock::SUCCESS 39 | : $transactionResult 40 | ]; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Gateway/Response/FraudHandler.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Gateway\Response; 8 | 9 | use Magento\Payment\Gateway\Data\PaymentDataObjectInterface; 10 | use Magento\Payment\Gateway\Response\HandlerInterface; 11 | use Magento\Sales\Model\Order\Payment; 12 | 13 | class FraudHandler implements HandlerInterface 14 | { 15 | const FRAUD_MSG_LIST = 'FRAUD_MSG_LIST'; 16 | 17 | /** 18 | * Handles fraud messages 19 | * 20 | * @param array $handlingSubject 21 | * @param array $response 22 | * @return void 23 | */ 24 | public function handle(array $handlingSubject, array $response) 25 | { 26 | if (!isset($response[self::FRAUD_MSG_LIST]) || !is_array($response[self::FRAUD_MSG_LIST])) { 27 | return; 28 | } 29 | 30 | if (!isset($handlingSubject['payment']) 31 | || !$handlingSubject['payment'] instanceof PaymentDataObjectInterface 32 | ) { 33 | throw new \InvalidArgumentException('Payment data object should be provided'); 34 | } 35 | 36 | /** @var PaymentDataObjectInterface $paymentDO */ 37 | $paymentDO = $handlingSubject['payment']; 38 | $payment = $paymentDO->getPayment(); 39 | 40 | $payment->setAdditionalInformation( 41 | self::FRAUD_MSG_LIST, 42 | (array)$response[self::FRAUD_MSG_LIST] 43 | ); 44 | 45 | /** @var $payment Payment */ 46 | $payment->setIsTransactionPending(true); 47 | $payment->setIsFraudDetected(true); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Gateway/Response/TxnIdHandler.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Gateway\Response; 8 | 9 | use Magento\Payment\Gateway\Data\PaymentDataObjectInterface; 10 | use Magento\Payment\Gateway\Response\HandlerInterface; 11 | 12 | class TxnIdHandler implements HandlerInterface 13 | { 14 | const TXN_ID = 'TXN_ID'; 15 | 16 | /** 17 | * Handles transaction id 18 | * 19 | * @param array $handlingSubject 20 | * @param array $response 21 | * @return void 22 | */ 23 | public function handle(array $handlingSubject, array $response) 24 | { 25 | if (!isset($handlingSubject['payment']) 26 | || !$handlingSubject['payment'] instanceof PaymentDataObjectInterface 27 | ) { 28 | throw new \InvalidArgumentException('Payment data object should be provided'); 29 | } 30 | 31 | /** @var PaymentDataObjectInterface $paymentDO */ 32 | $paymentDO = $handlingSubject['payment']; 33 | 34 | $payment = $paymentDO->getPayment(); 35 | 36 | /** @var $payment \Magento\Sales\Model\Order\Payment */ 37 | $payment->setTransactionId($response[self::TXN_ID]); 38 | $payment->setIsTransactionClosed(false); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Helper/Data.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Helper; 8 | 9 | use Magento\Framework\App\Helper\AbstractHelper; 10 | use Magento\Framework\App\Helper\Context; 11 | use Magento\Store\Model\ScopeInterface; 12 | use Firebear\ShapeShift\Model\CurrencyConverter\CoinMarketCapFactory; 13 | use Firebear\ShapeShift\Model\Client\ShapeShiftClientApiFactory; 14 | use Magento\Framework\Math\Division; 15 | 16 | class Data extends AbstractHelper 17 | { 18 | const XML_PATH_CONFIG_COINPAYMENTS = 'payment/shape_shift/'; 19 | 20 | private $converter; 21 | private $log; 22 | private $division; 23 | private $shapeShiftClientApiFactory; 24 | 25 | /** 26 | * Data constructor. 27 | * 28 | * @param Context $context 29 | */ 30 | public function __construct( 31 | Context $context, 32 | CoinMarketCapFactory $converter, 33 | Division $division, 34 | ShapeShiftClientApiFactory $shapeShiftClientApiFactory 35 | ) { 36 | parent::__construct($context); 37 | $this->converter = $converter; 38 | $this->division = $division; 39 | $this->shapeShiftClientApiFactory = $shapeShiftClientApiFactory; 40 | } 41 | 42 | /** 43 | * @param $field 44 | * @param null $storeId 45 | * 46 | * @return mixed 47 | */ 48 | private function getConfigValue($field, $storeId = null) 49 | { 50 | return $this->scopeConfig->getValue( 51 | $field, 52 | ScopeInterface::SCOPE_STORE, 53 | $storeId 54 | ); 55 | } 56 | 57 | /** 58 | * @param $code 59 | * @param null $storeId 60 | * 61 | * @return mixed 62 | */ 63 | public function getGeneralConfig($code, $storeId = null) 64 | { 65 | return $this->getConfigValue(self::XML_PATH_CONFIG_COINPAYMENTS . $code, $storeId); 66 | } 67 | 68 | public function convertCurrency($amount, $currency, $selectCoin) 69 | { 70 | $shapeShiftClientApi = $this->shapeShiftClientApiFactory->create(); 71 | $currencyName = $shapeShiftClientApi->getCurrencyFullName($selectCoin); 72 | $this->_logger->info("SELECT CURRENCY NAME: ".$currencyName); 73 | $converterModel = $this->converter->create(); 74 | $jsonData = $converterModel->getCurrencyTicker(strtolower($currencyName), $currency); 75 | 76 | return number_format($amount / $jsonData[0]['price_usd'], 10); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Model/Adminhtml/Source/CryptoCurrency.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Model\Adminhtml\Source; 8 | 9 | use Magento\Payment\Model\Method\AbstractMethod; 10 | use Firebear\ShapeShift\Model\Client\ShapeShiftClientApiFactory; 11 | 12 | /** 13 | * Class PaymentAction 14 | */ 15 | class CryptoCurrency implements \Magento\Framework\Option\ArrayInterface 16 | { 17 | private $shapeShiftClientApiFactory; 18 | 19 | public function __construct(ShapeShiftClientApiFactory $shapeShiftClientApiFactory) 20 | { 21 | $this->shapeShiftClientApiFactory = $shapeShiftClientApiFactory; 22 | } 23 | /** 24 | * {@inheritdoc} 25 | */ 26 | public function toOptionArray() 27 | { 28 | $shapeShiftClientApiModel = $this->shapeShiftClientApiFactory->create(); 29 | $optionArray = $shapeShiftClientApiModel->getAvailableCurrency('adminhtml'); 30 | return $optionArray; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Model/Adminhtml/Source/PaymentAction.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Model\Adminhtml\Source; 8 | 9 | use Magento\Payment\Model\Method\AbstractMethod; 10 | 11 | /** 12 | * Class PaymentAction 13 | */ 14 | class PaymentAction implements \Magento\Framework\Option\ArrayInterface 15 | { 16 | /** 17 | * {@inheritdoc} 18 | */ 19 | public function toOptionArray() 20 | { 21 | return [ 22 | [ 23 | 'value' => AbstractMethod::ACTION_AUTHORIZE, 24 | 'label' => __('Authorize') 25 | ] 26 | ]; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Model/Client/ShapeShiftClientApi.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Model\Client; 8 | 9 | use Firebear\ShapeShift\Helper\Data; 10 | use Psr\Log\LoggerInterface; 11 | 12 | class ShapeShiftClientApi 13 | { 14 | private $helper; 15 | private $pair; 16 | public $depoAddress; 17 | public $depoAmount; 18 | private $log; 19 | public $error; 20 | 21 | public function __construct(Data $helper, LoggerInterface $log) 22 | { 23 | $this->helper = $helper; 24 | $this->log = $log; 25 | } 26 | 27 | public function sendFixedAmount($amount, $withdrawAdd, $returnAdd, $inputCrypto, $outputCrypto) 28 | { 29 | $this->log->info("sendFixedAmount() 1"); 30 | $this->pairing($inputCrypto, $outputCrypto); 31 | $this->log->info("sendFixedAmount() 2"); 32 | $data = [ 33 | "amount" => $amount, 34 | "withdrawal" => $withdrawAdd, 35 | "pair" => $this->pair, 36 | "returnAddress" => $returnAdd, 37 | "apiKey" => $this->helper->getGeneralConfig('apikey') 38 | ]; 39 | $this->log->info("sendFixedAmount() 3"); 40 | $responseArray = $this->sendReqestPost($this->helper->getGeneralConfig('sendamount'), json_encode($data)); 41 | $this->log->info("sendFixedAmount() DATA: ", $responseArray); 42 | if (isset($responseArray['error'])) { 43 | $this->setError( 44 | $responseArray['error'], 45 | $this->helper->getGeneralConfig('sendamount') 46 | ); 47 | } else { 48 | if (!isset($responseArray['success']['deposit'])) { 49 | $this->setError( 50 | 'Payment method is not available. Deposit address not set.', 51 | $this->helper->getGeneralConfig('sendamount') 52 | ); 53 | } else { 54 | $this->depoAddress = $responseArray['success']['deposit']; 55 | $this->depoAmount = $responseArray['success']['depositAmount']; 56 | } 57 | } 58 | 59 | } 60 | 61 | public function getAvailableCurrency($versionArray = '') 62 | { 63 | $responseArray = $this->sendReqestGet($this->helper->getGeneralConfig('getcoins')); 64 | $arrayAvailableCurrency = []; 65 | $arrayAvailableCurrencyAll = []; 66 | foreach ($responseArray as $k => $currency) { 67 | if ($versionArray == 'adminhtml') { 68 | $arrayAvailableCurrency[] = ['label' => $k, 'value' => strtolower($k)]; 69 | } else { 70 | $arrayAvailableCurrencyAll[strtolower($k)] = $k; 71 | } 72 | } 73 | 74 | if ($versionArray != 'adminhtml') { 75 | $currencyAvailable = explode(',', $this->helper->getGeneralConfig('allowcurrency')); 76 | if ($this->helper->getGeneralConfig('allowcurrency')) { 77 | foreach ($currencyAvailable as $currency) { 78 | $arrayAvailableCurrency[$currency] = strtoupper($currency); 79 | } 80 | } else { 81 | $arrayAvailableCurrency = $arrayAvailableCurrencyAll; 82 | } 83 | } 84 | 85 | 86 | return $arrayAvailableCurrency; 87 | } 88 | 89 | public function getPaymentDescription() 90 | { 91 | return $this->helper->getGeneralConfig('description'); 92 | } 93 | 94 | public function getCurrencyFullName($code) 95 | { 96 | $responseArray = $this->sendReqestGet($this->helper->getGeneralConfig('getcoins')); 97 | 98 | return $responseArray[strtoupper($code)]['name']; 99 | } 100 | 101 | public function getStatus($depositAddress) 102 | { 103 | $responseArray = $this->sendReqestGet($this->helper->getGeneralConfig('txstatus') . $depositAddress); 104 | 105 | return $responseArray['status']; 106 | } 107 | 108 | private function sendReqestPost($url, $data) 109 | { 110 | $ch = $this->getCurl(); 111 | curl_setopt($ch, CURLOPT_URL, $url); 112 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 113 | curl_setopt($ch, CURLOPT_HEADER, false); 114 | 115 | curl_setopt($ch, CURLOPT_POST, true); 116 | 117 | curl_setopt( 118 | $ch, 119 | CURLOPT_POSTFIELDS, 120 | $data 121 | ); 122 | 123 | curl_setopt( 124 | $ch, 125 | CURLOPT_HTTPHEADER, 126 | array( 127 | "Content-Type: application/json" 128 | ) 129 | ); 130 | 131 | $response = curl_exec($ch); 132 | curl_close($ch); 133 | 134 | return json_decode($response, true); 135 | } 136 | 137 | private function sendReqestGet($url) 138 | { 139 | $ch = $this->getCurl(); 140 | 141 | curl_setopt($ch, CURLOPT_URL, $url); 142 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 143 | curl_setopt($ch, CURLOPT_HEADER, false); 144 | 145 | $response = curl_exec($ch); 146 | curl_close($ch); 147 | 148 | return json_decode($response, true); 149 | } 150 | 151 | private function getCurl() 152 | { 153 | return curl_init(); 154 | } 155 | 156 | private function pairing($inputCrypto, $outputCrypto) 157 | { 158 | $this->pair = $inputCrypto . "_" . $outputCrypto; 159 | } 160 | 161 | private function setError($error, $url) 162 | { 163 | $this->error['error'] = $error; 164 | $this->error['url'] = $url; 165 | } 166 | } -------------------------------------------------------------------------------- /Model/Config/Allowcurrency.php: -------------------------------------------------------------------------------- 1 | shapeShiftClientApiFactory = $shapeShiftClientApiFactory; 19 | } 20 | 21 | /** 22 | * {@inheritdoc} 23 | */ 24 | public function toOptionArray() 25 | { 26 | $shapeShiftClientApiModel = $this->shapeShiftClientApiFactory->create(); 27 | return $shapeShiftClientApiModel->getAvailableCurrency('adminhtml'); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Model/CurrencyConverter/CoinMarketCap.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Model\CurrencyConverter; 8 | 9 | use Firebear\ShapeShift\Model\CurrencyConverter\Request; 10 | 11 | class CoinMarketCap 12 | { 13 | 14 | const API_URL = "https://api.coinmarketcap.com/v1/"; 15 | 16 | /** 17 | * Returns Ticker data. 18 | * 19 | * @param int $limit only returns the top limit results. 20 | * @param string $convert return price, 24h volume, and market cap in terms 21 | * of another currency. 22 | * Valid values are: 23 | * "AUD", "BRL", "CAD", "CHF", "CNY", "EUR", "GBP", "HKD", "IDR", 24 | * "INR", "JPY", "KRW", "MXN", "RUB" 25 | * 26 | * @return array 27 | */ 28 | public static function getTicker($limit = 10, $convert = "USD") 29 | { 30 | return Request::exec( 31 | self::API_URL . "ticker/", 32 | [ 33 | 'limit' => $limit, 34 | 'convert' => $convert 35 | ] 36 | ); 37 | } 38 | 39 | /** 40 | * Returns specified currency Ticker data. 41 | * 42 | * @param string $currency Currency name. 43 | * @param string $convert return price, 24h volume, and market cap in terms 44 | * of another currency. 45 | * Valid values are: 46 | * "AUD", "BRL", "CAD", "CHF", "CNY", "EUR", "GBP", "HKD", "IDR", 47 | * "INR", "JPY", "KRW", "MXN", "RUB" 48 | * 49 | * @return array 50 | */ 51 | public static function getCurrencyTicker($currency = "bitcoin", $convert = "USD") 52 | { 53 | if ($currency == 'ether') { 54 | $currency = 'ethereum'; 55 | } 56 | 57 | return Request::exec( 58 | self::API_URL . "ticker/{$currency}/", 59 | [ 60 | 'convert' => $convert 61 | ] 62 | ); 63 | } 64 | 65 | /** 66 | * Returns global data. 67 | * 68 | * @param string $convert return price, 24h volume, and market cap in terms 69 | * of another currency. 70 | * Valid values are: 71 | * "AUD", "BRL", "CAD", "CHF", "CNY", "EUR", "GBP", "HKD", "IDR", 72 | * "INR", "JPY", "KRW", "MXN", "RUB" 73 | * 74 | * @return array 75 | */ 76 | public static function getGlobalData($convert = "USD") 77 | { 78 | return Request::exec( 79 | self::API_URL . "global/", 80 | [ 81 | 'convert' => $convert 82 | ] 83 | ); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /Model/CurrencyConverter/Request.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Model\CurrencyConverter; 8 | 9 | 10 | class Request { 11 | 12 | /** 13 | * cURL handle. 14 | * 15 | * @var resource 16 | */ 17 | private static $ch = null; 18 | 19 | /** 20 | * Executes curl request to the CoinMarketCap API. 21 | * 22 | * @param array $req Request parameters list. 23 | * 24 | * @return array JSON data. 25 | * @throws \Exception If Curl error or CoinMarketCap API error occurred. 26 | */ 27 | public static function exec($url, array $req = []) { 28 | usleep(120000); 29 | 30 | // generate the POST data string 31 | $postData = http_build_query($req, '', '&'); 32 | 33 | // curl handle (initialize if required) 34 | if (is_null(self::$ch)) { 35 | self::$ch = curl_init(); 36 | curl_setopt(self::$ch, CURLOPT_RETURNTRANSFER, true); 37 | curl_setopt( 38 | self::$ch, 39 | CURLOPT_USERAGENT, 40 | 'Mozilla/4.0 (compatible; CoinMarketCap PHP API; ' . php_uname('a') . '; PHP/' . phpversion() . ')' 41 | ); 42 | } 43 | curl_setopt(self::$ch, CURLOPT_URL, $url . "?" . $postData); 44 | curl_setopt(self::$ch, CURLOPT_SSL_VERIFYPEER, false); 45 | 46 | // run the query 47 | $res = curl_exec(self::$ch); 48 | if ($res === false) { 49 | throw new \Exception("Curl error: " . curl_error(self::$ch)); 50 | } 51 | 52 | $json = json_decode($res, true); 53 | 54 | // Check for the CoinMarketCap API error 55 | if (isset($json['error'])) { 56 | throw new \Exception("CoinMarketCap API error: {$json['error']}"); 57 | } 58 | 59 | return $json; 60 | } 61 | 62 | /** 63 | * Executes simple GET request to the CoinMarketCap public API. 64 | * 65 | * @param string $url API method URL. 66 | * 67 | * @return array JSON data. 68 | */ 69 | public static function json($url) { 70 | $opts = [ 71 | 'http' => [ 72 | 'method' => 'GET', 73 | 'timeout' => 10 74 | ] 75 | ]; 76 | $context = stream_context_create($opts); 77 | $feed = file_get_contents($url, false, $context); 78 | $json = json_decode($feed, true); 79 | 80 | return $json; 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /Model/ResourceModel/Transactions.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Model\ResourceModel; 8 | 9 | use Magento\Framework\Model\ResourceModel\Db\AbstractDb; 10 | 11 | class Transactions extends AbstractDb 12 | { 13 | protected function _construct() 14 | { 15 | $this->_init('firebear_transaction_entity', 'id'); 16 | } 17 | } -------------------------------------------------------------------------------- /Model/ResourceModel/Transactions/Collection.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Model\ResourceModel\Transactions; 8 | 9 | use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; 10 | 11 | class Collection extends AbstractCollection 12 | { 13 | 14 | protected $_idFieldName = 'id'; 15 | 16 | /** 17 | * Define resource model 18 | * 19 | * @return void 20 | */ 21 | protected function _construct() 22 | { 23 | $this->_init('Firebear\ShapeShift\Model\Transactions', 'Firebear\ShapeShift\Model\ResourceModel\Transactions'); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Model/Transactions.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Model; 8 | 9 | /** 10 | * Class Transactions 11 | * 12 | * @package Firebear\ShapeShift\Model 13 | */ 14 | class Transactions extends \Magento\Framework\Model\AbstractModel 15 | implements \Firebear\ShapeShift\Api\Data\TransactionInterface 16 | { 17 | protected function _construct() 18 | { 19 | $this->_init('Firebear\ShapeShift\Model\ResourceModel\Transactions'); 20 | } 21 | 22 | public function __construct( 23 | \Magento\Framework\Model\Context $context, 24 | \Magento\Framework\Registry $registry, 25 | \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, 26 | \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, 27 | array $data = [] 28 | ) { 29 | parent::__construct($context, $registry, $resource, $resourceCollection, $data); 30 | } 31 | 32 | /** 33 | * {@inheritdoc} 34 | */ 35 | public function getId() 36 | { 37 | return $this->getData(self::ENTITY_ID); 38 | } 39 | 40 | /** 41 | * {@inheritdoc} 42 | */ 43 | public function setId($id) 44 | { 45 | return $this->setData(self::ENTITY_ID, $id); 46 | } 47 | 48 | /** 49 | * {@inheritdoc} 50 | */ 51 | public function getOrderId() 52 | { 53 | return $this->getData(self::ORDER_ID); 54 | } 55 | 56 | /** 57 | * {@inheritdoc} 58 | */ 59 | public function setOrderId($orderId) 60 | { 61 | return $this->setData(self::ORDER_ID, $orderId); 62 | } 63 | 64 | /** 65 | * {@inheritdoc} 66 | */ 67 | public function getDepositAddress() 68 | { 69 | return $this->getData(self::DEPOSIT_ADDRESS); 70 | } 71 | 72 | /** 73 | * {@inheritdoc} 74 | */ 75 | public function setDepositAddress($depositAddress) 76 | { 77 | return $this->setData(self::DEPOSIT_ADDRESS, $depositAddress); 78 | } 79 | 80 | /** 81 | * {@inheritdoc} 82 | */ 83 | public function getAmountDeposit() 84 | { 85 | return $this->getData(self::AMOUNT_DEPOSIT); 86 | } 87 | 88 | /** 89 | * {@inheritdoc} 90 | */ 91 | public function setAmountDeposit($amountDeposit) 92 | { 93 | return $this->setData(self::AMOUNT_DEPOSIT, $amountDeposit); 94 | } 95 | 96 | /** 97 | * {@inheritdoc} 98 | */ 99 | public function getStatus() 100 | { 101 | return $this->getData(self::STATUS); 102 | } 103 | 104 | /** 105 | * {@inheritdoc} 106 | */ 107 | public function setStatus($status) 108 | { 109 | return $this->setData(self::STATUS, $status); 110 | } 111 | } -------------------------------------------------------------------------------- /Model/TransactionsRepository.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Model; 8 | 9 | use Firebear\ShapeShift\Api\Data; 10 | use Magento\Framework\Config\Dom\ValidationException; 11 | use Magento\Framework\Exception\CouldNotDeleteException; 12 | use Magento\Framework\Exception\CouldNotSaveException; 13 | use Magento\Framework\Exception\NoSuchEntityException; 14 | use Psr\Log\LoggerInterface; 15 | 16 | class TransactionsRepository implements \Firebear\ShapeShift\Api\TransactionsRepositoryInterface 17 | { 18 | protected $transactionsModelResource; 19 | protected $transactionsModelFactory; 20 | private $log; 21 | 22 | /** 23 | * TransactionsRepository constructor. 24 | * 25 | * @param ResourceModel\Transactions $transactionsModelResource 26 | * @param TransactionsFactory $transactionsModelFactory 27 | */ 28 | public function __construct( 29 | \Firebear\ShapeShift\Model\ResourceModel\Transactions $transactionsModelResource, 30 | \Firebear\ShapeShift\Model\TransactionsFactory $transactionsModelFactory, 31 | LoggerInterface $log 32 | ) { 33 | $this->transactionsModelResource = $transactionsModelResource; 34 | $this->transactionsModelFactory = $transactionsModelFactory; 35 | $this->log = $log; 36 | } 37 | 38 | 39 | /** 40 | * @param Data\TransactionInterface $transactionModel 41 | * 42 | * @return Data\TransactionInterface 43 | * @throws CouldNotSaveException 44 | */ 45 | public function save(Data\TransactionInterface $transactionModel) 46 | { 47 | if ($transactionModel->getId()) { 48 | $transactionModel = $this->get($transactionModel->getId()) 49 | ->addData($transactionModel->getData()); 50 | } 51 | try { 52 | $this->transactionsModelResource->save($transactionModel); 53 | unset($this->entities); 54 | } catch (ValidationException $e) { 55 | $this->log->info("REPOSITORY SAVE: ".$e->getMessage()); 56 | throw new CouldNotSaveException(__($e->getMessage())); 57 | } catch (\Exception $e) { 58 | $this->log->info("REPOSITORY SAVE: ".__('Unable to save model %1', $transactionModel->getId())); 59 | throw new CouldNotSaveException(__('Unable to save model %1', $transactionModel->getId())); 60 | } 61 | 62 | return $transactionModel; 63 | } 64 | 65 | /** 66 | * @param int $id 67 | * 68 | * @return bool|mixed 69 | */ 70 | public function get($id) 71 | { 72 | if (!isset($this->entities[$id])) { 73 | $transactionModel = $this->transactionsModelFactory->create(); 74 | $this->transactionsModelResource->load($transactionModel, $id); 75 | if (!$transactionModel->getId()) { 76 | return false; 77 | } 78 | $this->entities[$id] = $transactionModel; 79 | } 80 | 81 | return $this->entities[$id]; 82 | } 83 | 84 | /** 85 | * @param $orderId 86 | * 87 | * @return mixed 88 | */ 89 | public function getByOrderId($orderId) 90 | { 91 | $model = $this->transactionsModelFactory->create(); 92 | $this->transactionsModelResource->load($model, $orderId, 'order_id'); 93 | $this->entities[$orderId] = $model; 94 | 95 | return $model; 96 | } 97 | 98 | /** 99 | * @return mixed 100 | */ 101 | public function create() 102 | { 103 | $model = $this->transactionsModelFactory->create(); 104 | 105 | return $model; 106 | } 107 | 108 | /** 109 | * @param int $itemId 110 | * 111 | * @return bool 112 | */ 113 | public function deleteById($id) 114 | { 115 | $model = $this->get($id); 116 | 117 | if ($this->delete($model)) { 118 | return true; 119 | } else { 120 | return false; 121 | } 122 | } 123 | 124 | /** 125 | * @param Data\BoxInterface $boxModel 126 | * 127 | * @return bool 128 | * @throws CouldNotSaveException 129 | */ 130 | public function delete(Data\TransactionInterface $transactionModel) 131 | { 132 | try { 133 | $this->transactionsModelResource->delete($transactionModel); 134 | } catch (ValidationException $e) { 135 | throw new CouldNotDeleteException(__($e->getMessage())); 136 | } catch (\Exception $e) { 137 | throw new CouldNotDeleteException(__('Unable to remove entity with ID "%1"', $transactionModel->getId())); 138 | } 139 | 140 | return true; 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /Model/Ui/ConfigProvider.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Model\Ui; 8 | 9 | use Magento\Checkout\Model\ConfigProviderInterface; 10 | use Firebear\ShapeShift\Model\Client\ShapeShiftClientApiFactory; 11 | 12 | /** 13 | * Class ConfigProvider 14 | */ 15 | class ConfigProvider implements ConfigProviderInterface 16 | { 17 | private $shapeShiftClientApiFactory; 18 | 19 | public function __construct(ShapeShiftClientApiFactory $shapeShiftClientApiFactory) 20 | { 21 | $this->shapeShiftClientApiFactory = $shapeShiftClientApiFactory; 22 | } 23 | 24 | const CODE = 'shape_shift'; 25 | 26 | /** 27 | * Retrieve assoc array of checkout configuration 28 | * 29 | * @return array 30 | */ 31 | public function getConfig() 32 | { 33 | $shapeShiftClientApiModel = $this->shapeShiftClientApiFactory->create(); 34 | $configArray = [ 35 | 'payment' => [ 36 | self::CODE => [ 37 | 'currencyCode' => $shapeShiftClientApiModel->getAvailableCurrency(), 38 | 'paymentDescription' => $shapeShiftClientApiModel->getPaymentDescription() 39 | ] 40 | ] 41 | ]; 42 | return $configArray; 43 | } 44 | } -------------------------------------------------------------------------------- /Observer/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firebearstudio/shapeshift-magento2/ac5b982e45073b00087e20cd87294c18db78e611/Observer/.DS_Store -------------------------------------------------------------------------------- /Observer/AfterPlaceOrder.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Observer; 8 | 9 | use Firebear\ShapeShift\Model\Client\ShapeShiftClientApiFactory; 10 | use Magento\Framework\Event\Observer; 11 | use Magento\Framework\Event\ObserverInterface; 12 | use Magento\Sales\Model\OrderRepository; 13 | 14 | class AfterPlaceOrder implements ObserverInterface 15 | { 16 | private $shapeShiftClientApi; 17 | private $registry; 18 | private $orderRepository; 19 | 20 | public function __construct( 21 | ShapeShiftClientApiFactory $shapeShiftClientApi, 22 | \Magento\Framework\Registry $registry, 23 | OrderRepository $orderRepository 24 | ) 25 | { 26 | $this->registry = $registry; 27 | $this->shapeShiftClientApi = $shapeShiftClientApi; 28 | $this->orderRepository = $orderRepository; 29 | } 30 | 31 | public function execute(Observer $observer) 32 | { 33 | foreach ($observer->getEvent()->getOrderIds() as $orderId) { 34 | $orderModel = $this->orderRepository->get($orderId); 35 | $additionalInformation = $orderModel->getPayment()->getAdditionalInformation(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Observer/DataAssignObserver.php: -------------------------------------------------------------------------------- 1 | 5 | */ 6 | 7 | namespace Firebear\ShapeShift\Observer; 8 | 9 | use Magento\Framework\Event\Observer; 10 | use Magento\Payment\Observer\AbstractDataAssignObserver; 11 | use Psr\Log\LoggerInterface; 12 | 13 | class DataAssignObserver extends AbstractDataAssignObserver 14 | { 15 | private $registry; 16 | private $logger; 17 | 18 | public function __construct( 19 | \Magento\Framework\Registry $registry, 20 | LoggerInterface $logger 21 | ) 22 | { 23 | $this->logger = $logger; 24 | $this->registry = $registry; 25 | } 26 | 27 | /** 28 | * @param Observer $observer 29 | * @return void 30 | */ 31 | public function execute(Observer $observer) 32 | { 33 | $method = $this->readMethodArgument($observer); 34 | $data = $this->readDataArgument($observer); 35 | $paymentInfo = $method->getInfoInstance(); 36 | $dataArray = $data->getDataByKey('additional_data'); 37 | if ($data->getDataByKey('transaction_result') !== null) { 38 | $paymentInfo->setAdditionalInformation( 39 | 'transaction_result', 40 | $dataArray['transaction_result'] 41 | ); 42 | $paymentInfo->setAdditionalInformation( 43 | 'return_address', 44 | $dataArray['return_address'] 45 | ); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Plugin/Payment/Model/Method/Adapter.php: -------------------------------------------------------------------------------- 1 | log = $log; 23 | $this->checkoutSession = $checkoutSession; 24 | $this->shapeShiftHelper = $shapeShiftHelper; 25 | } 26 | 27 | public function aroundIsAvailable( 28 | \Magento\Payment\Model\Method\Adapter $subject, 29 | callable $proceed, 30 | CartInterface $quote = null 31 | ) { 32 | if ($subject->getCode() == 'shape_shift') { 33 | $quote = $this->checkoutSession->getQuote(); 34 | $country = $quote->getBillingAddress()->getCountry(); 35 | if ($this->shapeShiftHelper->getGeneralConfig('allowspecific')) { 36 | $allowedCountry = explode(',', $this->shapeShiftHelper->getGeneralConfig('specificcountry')); 37 | if (!in_array($country, $allowedCountry)) { 38 | return false; 39 | } 40 | } 41 | if ($quote->getGrandTotal() > $this->shapeShiftHelper->getGeneralConfig('max_limit_price') 42 | || $quote->getGrandTotal() < $this->shapeShiftHelper->getGeneralConfig('min_limit_price')) { 43 | return false; 44 | } 45 | } 46 | $returnValue = $proceed(); 47 | 48 | return $returnValue; 49 | } 50 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ShapeShift for Magento2 - Accept BitCoin, Ethereum and other cryptocurrencies without transations fee and registration 2 | 3 | 4 | 5 | - Accept all possible altcoins on Magento 2 websites; 6 | - Support for all major cryptocurrencies; 7 | - No login or registration; 8 | - No transaction fee; 9 | - Deposit minimum/maximum; 10 | - No need to use multiple wallets, code branches or databases; 11 | - Magento 2 payment method developed with the best practices in mind; 12 | - Easy integration 13 | - 100% Free & Open Source - available on GitHub 14 | 15 | Video overview 16 | 17 | Extension compatible with all recent versions of Magento 2.0.x , 2.1.x, 2.2.x Open Source (Community), Commerce (Enterprise) and Cloud Edition! 18 | 19 | At this moment to accept BitCoin (BTC) with this extension you need to enter wallet of different cryptocurrency to receive (we advise Ethereum) - amounts of placed orders will be converted automatically without additional fees (only miner fee) by ShapeShift. Currently, BitCoins fee are very high and also network is slow, so consider Ethereum and other altcoins! 20 | 21 | Alternative payment gateway where you can directly accept BitCoin and altcoins with registration, friendly interface, and withdrawal to fiat - CoinPayments for Magento 2 22 | 23 | Stay up to date about the crypto by follow top communities on Reddit - Cryptocurrency | Ethereum | BitCoin 24 | 25 | Accept cryptocurrency payments on Magento 2 by ShapeShift exchange API. Read more on our blog 26 | 27 | Meet the advanced Bitcoin payment option for your ecommerce website - ShapeShift Magento 2 extension. It is a cryptocurrency converter that supports Bitcoin, Ethereum, and tons of other altcoins. Learn what is BitCoin and create BitCoin wallet - https://www.bitcoin.com/ 28 | 29 | ShapeShift collects neither personal data nor customer funds: the exchange takes place beyond company accounts. Note that most digital currency trading companies collect both information and funds, so ShapeShift introduces a great competitive advantage over them making transactions much more secure. 30 | 31 | It doesn’t require name, email, or location to send funds. A specific address to which you should send funds. The need to create an account to run a transaction is completely eliminated. 32 | A “No Fiat” policy is another feature of the platform and module. But you can run fiat withdrawal via other services that support fiat, for instance, Coinbase. Thus, the usage of banks or political currencies is eliminated within the platform. 33 | 34 | With ShapeShift, what you see is what you get. The exchange rate shown is exactly what you'll receive, minus only the "miner fee." So you don't pay any transaction fee which is typical for traditional payment gateways! Learn more - https://info.shapeshift.io/about 35 | 36 | Supported coins : 1ST,ANT,BAT,BCH,BTC,BCY,BLK,BNT,BTS,CLAM,CVC,DASH,DCR,DGB,DGD,DOGE,EDG,EMC,EOS,ETH,ETC,FCT,FUN,GAME,GNO,GNT,GUP,ICN,KMD,LBC,LSK,LTC,MAID,MLN,MSCN,MONA,MTL,NMC,NMR,NVC,PAY,USNBT,NXT,OMG,POT,PPC,QTUM,RDD,REP,RLC,SC,SJCX,SNGLS,SNT,START,STEEM,SWT,TKN,USDT,VRC,VTC,VOX,TRST,WAVES,WINGS,XCP,XMR,XRP,ZEC,ZRX 37 | Learn more about all coins & see current exchange rate on CoinMarketCap 38 | 39 | ShapeShift for Magento 2 Installation 40 | 41 | Run: 42 | ``` 43 | composer require firebear/shapeshift 44 | ``` 45 | ``` 46 | php -f bin/magento setup:upgrade 47 | ``` 48 | ``` 49 | php -f bin/magento setup:static-content:deploy 50 | ``` 51 | ``` 52 | php -f bin/magento cache:clean 53 | ``` 54 | Checkout integration 55 | 56 | To improve the default shopping experience of Magento 2, the Firebear ShapeShift extension adds a new payment method to the checkout page. Customers can select it after completing the first checkout step. It is necessary to specify a cryptocurrency to place the order as well as a return address to enable further refund. 57 | 58 | Magento 2 BitCoin & Ethereum checkout 59 | 60 | To continue the checkout procedure, a customer should hit the ‘Place Order’ button that redirects a buyer to a new screen. On this screen, a deposit address and a required amount of altcoins are displayed. This information is necessary to complete the order. 61 | 62 | place order with BitCoin Magento 2 63 | 64 | As for additional order details and tracking, they are provided via email. 65 | 66 | Backend configuration 67 | 68 | Now, let’s tell a few words about the backend configuration of the Firebear Magento 2 ShapeShift extension. Everything is even easier here. From the perspective of a store administrator, the configuration of the ShapeShift Magento 2 extension doesn’t takes too much time and effort. All the necessary settings are available under Stores -> Settings -> Configuration -> Sales -> Payment Methods -> Other Payment Methods. There is a new payment method called ‘Shape Shift Payment’. The appropriate tab allows you enabling the extension and selecting the desired cryptocurrency you want to get after the payment is processed. The ShapeShift Magento 2 module supports all existing altcoins. Of course, you can select Bitcoin or Ethereum as a basis of all operations, but the plugin offers much wider opportunities. Next, specify a wallet deposit address. Remember that it must be related to the specified coin type. 69 | 70 | Magento 2 BitCoin extgension configuration 71 | 72 | Next, it is necessary to specify a paid order status, turn the debugging on or off, and select a payment action. 73 | 74 | BitCoin order status Magento 2 75 | 76 | Also specify countries to allows the new payment method. Note that you can enable the ShapeShift payment method for all countries or select ones that suits your ecommerce requirements. Set the priority of the new payment method. That’s the end of the configuration. 77 | 78 | Magento 2 bitcoin payment settings 79 | 80 | Let’s compare the ShapeShift Magento 2 extension with the FireBear CoinPayments for Magento 2 extension. Both extensions allows you to accept cryptocurrencies on the basis of a Magento 2 website in a very user-friendly manner, but both have some unique features. While CoinPayments offers a user-friendly web interface, it is necessary to complete the additional checkout steps outside of the Magento 2 website within a customer-friendly interface, so your clients can easily complete the purchase. You get a wallet for cryptocurrencies and can withdraw them as a fiat currency (the commission is 0.5%) right to a bank account. The registration on the platform is required. 81 | In its turn ShapeShift doesn't require any registrations, but provides neither wallets (so a third-party wallet is necessary), nor the ability to withdraw fiat money. You can accept altcoins right after the module is installed and there is no limitation in terms of supported altcoins. Any coins used by your customers to complete the purchase will be converted into the specified cryptocurrency. For further information, check the extension manual or contact us 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /Setup/InstallSchema.php: -------------------------------------------------------------------------------- 1 | startSetup(); 19 | $table = $setup->getConnection()->newTable( 20 | $setup->getTable('firebear_transaction_entity') 21 | )->addColumn( 22 | 'id', 23 | \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, 24 | null, 25 | ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], 26 | 'Id' 27 | )->addColumn( 28 | 'order_id', 29 | \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, 30 | null, 31 | [], 32 | 'Order Id' 33 | )->addColumn( 34 | 'deposit_address', 35 | \Magento\Framework\Db\Ddl\Table::TYPE_TEXT, 36 | null, 37 | [], 38 | 'Deposit address' 39 | )->addColumn( 40 | 'amount_deposit', 41 | \Magento\Framework\Db\Ddl\Table::TYPE_FLOAT, 42 | null, 43 | [], 44 | 'Amount deposit coins to deposit address' 45 | )->addColumn( 46 | 'status', 47 | \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, 48 | null, 49 | [], 50 | 'Status code' 51 | )->setComment( 52 | 'Aitoc Dimensional Shipping order boxes' 53 | ); 54 | $setup->getConnection()->createTable($table); 55 | 56 | 57 | $setup->endSetup(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "firebear/shapeshift", 3 | "description": "Add new payment method for https://www.shapeshifth.io", 4 | "require": { 5 | "php": "~5.5.0|~5.6.0|~7.0.0|~7.1" 6 | }, 7 | "type": "magento2-module", 8 | "version": "1.0.16", 9 | "license": [ 10 | "OSL-3.0" 11 | ], 12 | "autoload": { 13 | "files": [ 14 | "registration.php" 15 | ], 16 | "psr-4": { 17 | "Firebear\\ShapeShift\\": "" 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /etc/adminhtml/di.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 0 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /etc/adminhtml/system.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 | 7 | 8 | 9 | Magento\Config\Model\Config\Source\Yesno 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | Firebear\ShapeShift\Model\Adminhtml\Source\CryptoCurrency 20 | 21 | 22 | 23 | 24 | 25 | 26 | Magento\Sales\Model\Config\Source\Order\Status 27 | 28 | 29 | 30 | Magento\Config\Model\Config\Source\Yesno 31 | 32 | 33 | 34 | Firebear\ShapeShift\Model\Adminhtml\Source\PaymentAction 35 | 36 | 37 | 38 | Firebear\ShapeShift\Model\Config\Allowcurrency 39 | 40 | 42 | 43 | Magento\Payment\Model\Config\Source\Allspecificcountries 44 | 45 | 47 | 48 | Magento\Directory\Model\Config\Source\Country 49 | 50 | 51 | 52 | validate-number 53 | 54 | 55 | 56 | validate-number 57 | 58 | 59 | 60 | validate-number 61 | 62 | 63 |
64 |
65 |
-------------------------------------------------------------------------------- /etc/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 11 | 12 | 13 | 0 14 | 1 15 | ShapeShiftGatewayFacade 16 | pending 17 | Shape Shift 18 | 0 19 | 1 20 | 1 21 | 1 22 | 1 23 | 1 24 | 1 25 | 2106861f10516dabde38412e6568a11890605ccea018377daf8fa4378eeed12f33a7b73bda9ed23250fbbedf939e5101be80218746ac97edca6ab96516d92f73 26 | https://shapeshift.io/sendamount 27 | https://shapeshift.io/getcoins 28 | https://shapeshift.io/txStat/ 29 | 0 30 | 1000 31 | ShapeShift cryptocurrency payment method 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /etc/cron_groups.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 1 11 | 4 12 | 2 13 | 10 14 | 60 15 | 600 16 | 1 17 | 18 | -------------------------------------------------------------------------------- /etc/crontab.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | * * * * * 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /etc/di.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | \Firebear\ShapeShift\Model\Ui\ConfigProvider::CODE 13 | Magento\Payment\Block\Form 14 | Firebear\ShapeShift\Block\Info 15 | ShapeShiftGatewayValueHandlerPool 16 | ShapeShiftGatewayCommandPool 17 | 18 | 19 | 20 | 21 | 22 | 23 | \Firebear\ShapeShift\Model\Ui\ConfigProvider::CODE 24 | 25 | 26 | 27 | 28 | 29 | 30 | ShapeShiftGatewayConfig 31 | 32 | 33 | 34 | 35 | 36 | ShapeShiftGatewayLogger 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | ShapeShiftGatewayAuthorizeCommand 45 | ShapeShiftGatewayCaptureCommand 46 | ShapeShiftGatewayVoidCommand 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | ShapeShiftGatewayAuthorizationRequest 55 | ShapeShiftGatewayResponseHandlerComposite 56 | Firebear\ShapeShift\Gateway\Http\TransferFactory 57 | Firebear\ShapeShift\Gateway\Http\Client\ClientMock 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | Firebear\ShapeShift\Gateway\Request\AuthorizationRequest 66 | Firebear\ShapeShift\Gateway\Request\MockDataRequest 67 | 68 | 69 | 70 | 71 | 72 | ShapeShiftGatewayConfig 73 | 74 | 75 | 76 | 77 | 78 | 79 | Magento\SamplePaymentGateway\Gateway\Request\CaptureRequest 80 | Firebear\ShapeShift\Gateway\Response\TxnIdHandler 81 | Firebear\ShapeShift\Gateway\Http\TransferFactory 82 | Magento\SamplePaymentGateway\Gateway\Validator\ResponseCodeValidator 83 | Firebear\ShapeShift\Gateway\Http\Client\ClientMock 84 | 85 | 86 | 87 | 88 | 89 | 90 | ShapeShiftGatewayConfig 91 | 92 | 93 | 94 | 95 | 96 | 97 | Magento\SamplePaymentGateway\Gateway\Request\VoidRequest 98 | Firebear\ShapeShift\Gateway\Response\TxnIdHandler 99 | Firebear\ShapeShift\Gateway\Http\TransferFactory 100 | Magento\SamplePaymentGateway\Gateway\Validator\ResponseCodeValidator 101 | Firebear\ShapeShift\Gateway\Http\Client\ClientMock 102 | 103 | 104 | 105 | 106 | 107 | 108 | ShapeShiftGatewayConfig 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | Firebear\ShapeShift\Gateway\Response\TxnIdHandler 117 | Firebear\ShapeShift\Gateway\Response\FraudHandler 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | ShapeShiftGatewayConfigValueHandler 127 | 128 | 129 | 130 | 131 | 132 | ShapeShiftGatewayConfig 133 | 134 | 135 | 136 | 137 | 138 | ShapeShiftGatewayConfig 139 | 140 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /etc/events.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /etc/frontend/di.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Firebear\ShapeShift\Model\Ui\ConfigProvider 8 | 9 | 10 | 11 | 12 | 13 | 14 | 1 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /etc/frontend/routes.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /registration.php: -------------------------------------------------------------------------------- 1 | getTemplateData(); 4 | ?> 5 | 6 | Method: ShapeShift 7 |

Transaction Information:

8 |

Address:

9 |

Amount:

10 | -------------------------------------------------------------------------------- /view/frontend/layout/checkout_index_index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | uiComponent 15 | 16 | 17 | 18 | 19 | 20 | 21 | Firebear_ShapeShift/js/view/payment/shape_shift 22 | 23 | 24 | true 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /view/frontend/layout/checkout_onepage_success.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /view/frontend/templates/info/shapeshift.phtml: -------------------------------------------------------------------------------- 1 | getTemplateData(); 4 | ?> 5 | 6 | Method: ShapeShift 7 |

Transaction Information:

8 |

Address:

9 |

Amount:

10 | -------------------------------------------------------------------------------- /view/frontend/templates/page/success.phtml: -------------------------------------------------------------------------------- 1 | getTransactionData(); ?> 2 | getData()): ?> 3 |
4 |

Your order was placed with ShapeShift.io payment.

5 |

Transaction information:

6 |

DepositAddress: getDepositAddress(); ?>

7 |

Amount: getAmountDeposit(); ?>

8 |
9 | -------------------------------------------------------------------------------- /view/frontend/web/js/view/payment/method-renderer/shape_shift.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Magento. All rights reserved. 3 | * See COPYING.txt for license details. 4 | */ 5 | /*browser:true*/ 6 | /*global define*/ 7 | define( 8 | [ 9 | 'ko', 10 | 'Magento_Checkout/js/view/payment/default', 11 | 'Magento_Checkout/js/model/quote', 12 | 'jquery', 13 | 'Magento_Checkout/js/action/place-order', 14 | 'Magento_Checkout/js/action/select-payment-method', 15 | 'Magento_Customer/js/model/customer', 16 | 'Magento_Checkout/js/checkout-data', 17 | 'Magento_Checkout/js/model/payment/additional-validators', 18 | 'mage/url', 19 | 'Magento_Checkout/js/model/full-screen-loader', 20 | 'Magento_Checkout/js/action/redirect-on-success' 21 | ], 22 | function (ko, Component, quote, $, placeOrderAction, selectPaymentMethodAction, customer, checkoutData, additionalValidators, url, fullScreenLoader, redirectOnSuccessAction) { 23 | 'use strict'; 24 | 25 | return Component.extend({ 26 | defaults: { 27 | template : 'Firebear_ShapeShift/payment/form', 28 | currencyCode : '', 29 | returnAddress : '', 30 | deposit : '', 31 | newErrorMessage: ko.observable(false) 32 | }, 33 | 34 | initObservable: function () { 35 | 36 | this._super() 37 | .observe([ 38 | 'currencyCode', 'returnAddress' 39 | ]); 40 | return this; 41 | }, 42 | 43 | getCode: function () { 44 | return 'shape_shift'; 45 | }, 46 | 47 | getData : function () { 48 | return { 49 | 'method' : this.item.method, 50 | 'additional_data': { 51 | 'currency_code' : this.currencyCode(), 52 | 'return_address': this.returnAddress() 53 | } 54 | }; 55 | }, 56 | afterPlaceOrder : function () { 57 | jQuery.ajax({ 58 | url : url.build('shapeshift/api/saveTransaction'), 59 | type : 'POST', 60 | dataType : 'json', 61 | showLoader: true, 62 | data : {"depoAmount": this.deposit.amount, "depoAddress": this.deposit.address} 63 | }); 64 | /*window.location.replace(url.build('shapeshift/page/success/'));*/ 65 | }, 66 | placeOrder : function (data, event) { 67 | var self = this; 68 | 69 | if (event) { 70 | event.preventDefault(); 71 | } 72 | if (this.currencyCode()) { 73 | jQuery.ajax({ 74 | url : url.build('shapeshift/api/index'), 75 | type : 'POST', 76 | dataType : "json", 77 | showLoader: true, 78 | data : {"returnAddress": this.returnAddress(), "currencyCode": this.currencyCode()}, 79 | success : function (data) { 80 | self.deposit = data; 81 | if (self.deposit.error) { 82 | self.isPlaceOrderActionAllowed(true); 83 | self.newErrorMessage('Message: ' + self.deposit.error + ' Request: ' + self.deposit.url); 84 | } 85 | else { 86 | if (self.validate() && additionalValidators.validate()) { 87 | self.isPlaceOrderActionAllowed(false); 88 | self.getPlaceOrderDeferredObject() 89 | .fail( 90 | function () { 91 | self.isPlaceOrderActionAllowed(true); 92 | } 93 | ).done(function () { 94 | self.afterPlaceOrder(); 95 | 96 | if (self.redirectAfterPlaceOrder) { 97 | redirectOnSuccessAction.execute(); 98 | } 99 | }); 100 | 101 | return true; 102 | } 103 | } 104 | } 105 | }); 106 | } 107 | else 108 | { 109 | self.isPlaceOrderActionAllowed(true); 110 | self.newErrorMessage('Message: Please select Currency code'); 111 | } 112 | 113 | return false; 114 | 115 | }, 116 | getPlaceOrderDeferredObject: function () { 117 | return $.when( 118 | placeOrderAction(this.getData(), this.messageContainer) 119 | ); 120 | }, 121 | 122 | getAvailableCurrency: function () { 123 | return _.map(window.checkoutConfig.payment.shape_shift.currencyCode, function (value, key) { 124 | return { 125 | 'value' : key, 126 | 'currency_code': value 127 | } 128 | }); 129 | }, 130 | 131 | getPaymentDescription: function () { 132 | return window.checkoutConfig.payment.shape_shift.paymentDescription; 133 | } 134 | }); 135 | } 136 | ); -------------------------------------------------------------------------------- /view/frontend/web/js/view/payment/shape_shift.js: -------------------------------------------------------------------------------- 1 | define( 2 | [ 3 | 'uiComponent', 4 | 'Magento_Checkout/js/model/payment/renderer-list' 5 | ], 6 | function (Component, 7 | rendererList) { 8 | 'use strict'; 9 | rendererList.push( 10 | { 11 | type : 'shape_shift', 12 | component: 'Firebear_ShapeShift/js/view/payment/method-renderer/shape_shift' 13 | } 14 | ); 15 | /** Add view logic here if needed */ 16 | return Component.extend({}); 17 | } 18 | ); -------------------------------------------------------------------------------- /view/frontend/web/template/payment/form.html: -------------------------------------------------------------------------------- 1 | 7 |
8 | 9 |
10 | 14 | 17 |
18 | 19 |
20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 |
32 | 33 |
34 | 37 | 38 |
39 | 48 |
49 |
50 |
51 | 55 |
56 | 57 |
58 |
59 | 60 |
61 |
62 | 70 |
71 |
72 |
73 |
--------------------------------------------------------------------------------