From 7fc6e4f91983df1a35b8ecdb65decacf65c689a4 Mon Sep 17 00:00:00 2001 From: Kotlyar Maksim Date: Mon, 1 Dec 2014 20:58:39 +0000 Subject: [PATCH 1/2] [bitcoind] add simple purchase example. --- app/config/parameters.yml.dist | 4 +- app/config/payum.yml | 4 + composer.json | 1 + composer.lock | 107 +++++++++--------- .../SimplePurchaseBitcoindController.php | 75 ++++++++++++ .../Resources/config/routing.yml | 4 + .../Resources/views/Default/index.html.twig | 5 + .../SimplePurchaseBitcoind/prepare.html.twig | 13 +++ 8 files changed, 157 insertions(+), 56 deletions(-) create mode 100644 src/Acme/PaymentBundle/Controller/SimplePurchaseBitcoindController.php create mode 100644 src/Acme/PaymentBundle/Resources/views/SimplePurchaseBitcoind/prepare.html.twig diff --git a/app/config/parameters.yml.dist b/app/config/parameters.yml.dist index c0626b9..d5ad5f5 100644 --- a/app/config/parameters.yml.dist +++ b/app/config/parameters.yml.dist @@ -44,4 +44,6 @@ parameters: redsys.merchant_code: EDIT ME redsys.terminal: EDIT ME - redsys.secret_key: EDIT ME \ No newline at end of file + redsys.secret_key: EDIT ME + + bitcoind.dsn: EDIT ME \ No newline at end of file diff --git a/app/config/payum.yml b/app/config/payum.yml index 775be72..8044399 100644 --- a/app/config/payum.yml +++ b/app/config/payum.yml @@ -190,6 +190,10 @@ payum: secret_key: %redsys.secret_key% sandbox: true + bitcoind: + bitcoind: + dsn: %bitcoind.dsn% + paypal_express_checkout_plus_cart: paypal_express_checkout_nvp: username: %paypal.express_checkout.username% diff --git a/composer.json b/composer.json index 7631b5b..1995927 100644 --- a/composer.json +++ b/composer.json @@ -37,6 +37,7 @@ "omnipay/stripe": "~2.0", "omnipay/paypal": "~2.0", "stripe/stripe-php": "~1.0", + "nbobtc/bitcoind-php": "~1.0", "phpunit/phpunit": "~4.0", "fabpot/php-cs-fixer": "~0.5.7" }, diff --git a/composer.lock b/composer.lock index db566a4..48e1213 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "6d6d5ecf6f6f3c12f89158a1e371f63f", + "hash": "f21b97264e1ce7b0e69996a41037f9b5", "packages": [ { "name": "ajbdev/authorizenet-php-api", @@ -39,60 +39,6 @@ ], "time": "2013-02-11 21:09:06" }, - { - "name": "alcohol/iso4217", - "version": "2.0.0", - "source": { - "type": "git", - "url": "https://github.com/alcohol/iso4217.git", - "reference": "905cb79050560c4cd60f65755eb48036b691878a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/alcohol/iso4217/zipball/905cb79050560c4cd60f65755eb48036b691878a", - "reference": "905cb79050560c4cd60f65755eb48036b691878a", - "shasum": "" - }, - "require": { - "php": "~5.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.0", - "squizlabs/php_codesniffer": "~2.0@dev" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Alcohol\\": "source/", - "Alcohol\\Tests\\": "tests/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Rob Bast", - "email": "rob.bast@gmail.com" - } - ], - "description": "ISO 4217 PHP Library", - "homepage": "http://alcohol.github.io/iso4217/", - "keywords": [ - "4217", - "ISO 4217", - "currencies", - "iso", - "library" - ], - "time": "2014-11-08 17:54:32" - }, { "name": "crevillo/payum-redsys", "version": "dev-master", @@ -1790,6 +1736,57 @@ ], "time": "2014-09-30 13:30:58" }, + { + "name": "nbobtc/bitcoind-php", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/nbobtc/bitcoind-php.git", + "reference": "e07a6d95b7aa84368bcf3601f3bc4fb0cee83306" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nbobtc/bitcoind-php/zipball/e07a6d95b7aa84368bcf3601f3bc4fb0cee83306", + "reference": "e07a6d95b7aa84368bcf3601f3bc4fb0cee83306", + "shasum": "" + }, + "require": { + "lib-curl": "*", + "php": ">=5.3.0" + }, + "require-dev": { + "phing/phing": "*", + "phpunit/phpunit": "*", + "sami/sami": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Nbobtc": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Joshua Estes" + } + ], + "description": "PHP Wrapper for a bitcoind daemon", + "homepage": "https://github.com/nbobtc/bitcoind-php", + "keywords": [ + "bitcoin", + "bitcoind" + ], + "time": "2014-08-10 17:31:29" + }, { "name": "omnipay/common", "version": "v2.3.1", diff --git a/src/Acme/PaymentBundle/Controller/SimplePurchaseBitcoindController.php b/src/Acme/PaymentBundle/Controller/SimplePurchaseBitcoindController.php new file mode 100644 index 0000000..1df240c --- /dev/null +++ b/src/Acme/PaymentBundle/Controller/SimplePurchaseBitcoindController.php @@ -0,0 +1,75 @@ +createPurchaseForm(); + $form->handleRequest($request); + if ($form->isValid()) { + $data = $form->getData(); + + $storage = $this->getPayum()->getStorage('Acme\PaymentBundle\Model\PaymentDetails'); + + $details = $storage->createModel(); + $details['amount'] = $data['amt']; + $storage->updateModel($details); + + $captureToken = $this->getTokenFactory()->createCaptureToken( + $paymentName, + $details, + 'acme_payment_details_view' + ); + + return $this->forward('PayumBundle:Capture:do', array( + 'payum_token' => $captureToken, + )); + } + + return $this->render('AcmePaymentBundle:SimplePurchaseBitcoind:prepare.html.twig', array( + 'form' => $form->createView(), + )); + } + + /** + * @return \Symfony\Component\Form\Form + */ + protected function createPurchaseForm() + { + return $this->createFormBuilder() + ->add('amt', null, array( + 'data' => '0.0001', + 'constraints' => array(new Range(array('max' => 1))) + )) + ->add('currency', null, array('data' => 'BTC', 'read_only' => true)) + + ->getForm() + ; + } + + /** + * @return RegistryInterface + */ + protected function getPayum() + { + return $this->get('payum'); + } + + /** + * @return GenericTokenFactoryInterface + */ + protected function getTokenFactory() + { + return $this->get('payum.security.token_factory'); + } +} diff --git a/src/Acme/PaymentBundle/Resources/config/routing.yml b/src/Acme/PaymentBundle/Resources/config/routing.yml index d770f50..96d8cc5 100644 --- a/src/Acme/PaymentBundle/Resources/config/routing.yml +++ b/src/Acme/PaymentBundle/Resources/config/routing.yml @@ -46,6 +46,10 @@ acme_payment_prepare_obtain_credit_card_paypal_pro: pattern: /payment/simple_purchase/paypal_express_pro/prepare-obtain-credit-card defaults: { _controller: AcmePaymentBundle:SimplePurchasePaypalPro:prepareObtainCreditCard } +acme_payment_prepare_simple_purchase_bitcoind: + pattern: /payment/simple_purchase/bitcoind/prepare + defaults: { _controller: AcmePaymentBundle:SimplePurchaseBitcoind:prepare } + acme_payment_details_view: pattern: /payment/details defaults: { _controller: AcmePaymentBundle:Details:view } diff --git a/src/Acme/PaymentBundle/Resources/views/Default/index.html.twig b/src/Acme/PaymentBundle/Resources/views/Default/index.html.twig index 519d4f8..244343d 100644 --- a/src/Acme/PaymentBundle/Resources/views/Default/index.html.twig +++ b/src/Acme/PaymentBundle/Resources/views/Default/index.html.twig @@ -48,6 +48,11 @@ Checkout example (delayed) +

Bitcoind

+
  • + Simple purchase +
  • +

    Authorize.Net

  • Ask for credit card on when needed diff --git a/src/Acme/PaymentBundle/Resources/views/SimplePurchaseBitcoind/prepare.html.twig b/src/Acme/PaymentBundle/Resources/views/SimplePurchaseBitcoind/prepare.html.twig new file mode 100644 index 0000000..ad87490 --- /dev/null +++ b/src/Acme/PaymentBundle/Resources/views/SimplePurchaseBitcoind/prepare.html.twig @@ -0,0 +1,13 @@ +{% extends "AcmePaymentBundle::layout.html.twig" %} + +{% block title "Payment demo - Simple purchase with Bitcoind - Prepare" %} + +{% block content %} +
    + {{ form_widget(form) }} + + +
    +{% endblock %} + +{% set code = code(_self) %} From 2007a2c09884602695944ff88788bc5dce511976 Mon Sep 17 00:00:00 2001 From: Kotlyar Maksim Date: Mon, 1 Dec 2014 21:00:23 +0000 Subject: [PATCH 2/2] fix --- .../Controller/SimplePurchaseBitcoindController.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Acme/PaymentBundle/Controller/SimplePurchaseBitcoindController.php b/src/Acme/PaymentBundle/Controller/SimplePurchaseBitcoindController.php index 1df240c..0f3bef0 100644 --- a/src/Acme/PaymentBundle/Controller/SimplePurchaseBitcoindController.php +++ b/src/Acme/PaymentBundle/Controller/SimplePurchaseBitcoindController.php @@ -3,7 +3,6 @@ use Payum\Core\Registry\RegistryInterface; use Payum\Core\Security\GenericTokenFactoryInterface; -use Payum\Core\Security\SensitiveValue; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Validator\Constraints\Range; use Symfony\Bundle\FrameworkBundle\Controller\Controller; @@ -35,7 +34,7 @@ public function prepareAction(Request $request) 'payum_token' => $captureToken, )); } - + return $this->render('AcmePaymentBundle:SimplePurchaseBitcoind:prepare.html.twig', array( 'form' => $form->createView(), ));