コード例 #1
0
 public function configure()
 {
     if (null !== ($response = $this->checkAuth(array(AdminResources::MODULE), array('BitpayPayments'), AccessManager::UPDATE))) {
         return $response;
     }
     $conf = new BitpayPaymentsConfig();
     $one_is_done = 0;
     $tab = "";
     $form = new \BitpayPayments\Form\ConfigureBitpayPayments($this->getRequest());
     try {
         $vform = $this->validateForm($form);
         $conf->setApiKey($vform->get('apiKey')->getData())->getPairingKey($vform->get('pairingKey')->getData())->write();
         $one_is_done = 1;
         $tab = "configure_account";
     } catch (\Exception $e) {
     }
     $form = new \BitpayPayments\Form\ConfigureSandboxBitpayPayments($this->getRequest());
     try {
         $vform = $this->validateForm($form);
         $tab = "configure_sandbox";
         $conf->setApiKeySandbox($vform->get('apiKey')->getData())->setPairingKeySandbox($vform->get('pairingKey')->getData())->setSandbox($vform->get('sandbox')->getData() ? "true" : "");
         $conf->write();
     } catch (\Exception $e) {
     }
     //Redirect to module configuration page
     $this->redirectToRoute("admin.module.configure", array(), array('module_code' => BitpayPayments::getModCode(true), 'current_tab' => $tab, '_controller' => 'Thelia\\Controller\\Admin\\ModuleController::configureAction'));
 }
コード例 #2
0
 /**
  * @param null $file
  */
 public function write()
 {
     $dbvals = $this->getDbValues();
     $isnew = array();
     foreach ($dbvals as $var) {
         /** @var BitpayPaymentsConfig $var */
         $isnew[$var->getName()] = true;
     }
     $this->pushValues();
     $vars = $this->getThisVars();
     foreach ($vars as $key => $value) {
         $tmp = new BitpayPaymentsConfig();
         $tmp->setNew(!isset($isnew[$key]));
         $tmp->setName($key);
         $tmp->setValue($value);
         $tmp->save();
     }
 }
コード例 #3
0
 /**
  * Exclude object from result
  *
  * @param   ChildBitpayPaymentsConfig $bitpayConfig Object to remove from the list of results
  *
  * @return ChildBitpayPaymentsConfigQuery The current query, for fluid interface
  */
 public function prune($bitpayConfig = null)
 {
     if ($bitpayConfig) {
         $this->addUsingAlias(BitpayPaymentsConfigTableMap::NAME, $bitpayConfig->getName(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
コード例 #4
0
 /**
  *
  *  Method used by payment gateway.
  *
  *  If this method return a \Thelia\Core\HttpFoundation\Response instance, this response is send to the
  *  browser.
  *
  *  In many cases, it's necessary to send a form to the payment gateway. On your response you can return this form already
  *  completed, ready to be sent
  *
  * @param  \Thelia\Model\Order $order processed order
  * @return null|\Thelia\Core\HttpFoundation\Response
  */
 public function pay(Order $order)
 {
     $this->loadBitpayKeys();
     $client = new \Bitpay\Client\Client();
     $adapter = new \Bitpay\Client\Adapter\CurlAdapter();
     $config = new BitpayPaymentsConfig();
     $config->pushValues();
     if ($config->getSandbox()) {
         $pairingKey = $config->getPairingKeySandbox();
         $apiKey = $config->getApiKeySandbox();
         $network = new \Bitpay\Network\Testnet();
         $environment = "Sandbox";
     } else {
         $pairingKey = $config->getPairingKey();
         $apiKey = $config->getApiKey();
         $network = new \Bitpay\Network\Livenet();
         $environment = "Live";
     }
     $client->setPrivateKey($this->privateKey);
     $client->setPublicKey($this->publicKey);
     $client->setNetwork($network);
     $client->setAdapter($adapter);
     if (!isset($apiKey) || $apiKey == '') {
         // must create API key
         if (!isset($pairingKey) || $pairingKey == '') {
             // error: no pairing key
             $error = "Thelia BitpayPayments error: No API key or pairing key for environment {$environment} provided.";
             Tlog::getInstance()->error($error);
             throw new \Exception($error);
         } else {
             // pairing key available, now trying to get an API key
             $sin = \Bitpay\SinKey::create()->setPublicKey($this->publicKey)->generate();
             try {
                 $token = $client->createToken(array('pairingCode' => $pairingKey, 'label' => 'Thelia BitpayPayments', 'id' => (string) $sin));
             } catch (\Exception $e) {
                 $request = $client->getRequest();
                 $response = $client->getResponse();
                 $error = 'Thelia BitpayPayments error:' . PHP_EOL . PHP_EOL . $request . PHP_EOL . PHP_EOL . $response . PHP_EOL . PHP_EOL;
                 Tlog::getInstance()->error($error);
                 throw new \Exception($error);
             }
             $config->setApiKeyCurrentEnvironment($token->getToken());
             $config->setPairingKeyCurrentEnvironment('');
         }
     }
     // token should be available now
     $token = new \Bitpay\Token();
     $token->setToken($config->getApiKeyCurrentEnvironment());
     $client->setToken($token);
     $invoice = new \Bitpay\Invoice();
     $item = new \Bitpay\Item();
     $item->setCode('testCode');
     $item->setDescription('Purchase');
     $item->setPrice($order->getTotalAmount());
     $invoice->setItem($item);
     $invoice->setCurrency(new \Bitpay\Currency($order->getCurrency()->getCode()));
     try {
         $client->createInvoice($invoice);
     } catch (\Exception $e) {
         $request = $client->getRequest();
         $response = $client->getResponse();
         $error = 'Thelia BitpayPayments error:' . PHP_EOL . PHP_EOL . $request . PHP_EOL . PHP_EOL . $response . PHP_EOL . PHP_EOL;
         Tlog::getInstance()->error($error);
         throw new \Exception($error);
     }
 }
コード例 #5
0
 /**
  *
  * in this function you add all the fields you need for your Form.
  * Form this you have to call add method on $this->formBuilder attribute :
  *
  * $this->formBuilder->add("name", "text")
  *   ->add("email", "email", array(
  *           "attr" => array(
  *               "class" => "field"
  *           ),
  *           "label" => "email",
  *           "constraints" => array(
  *               new \Symfony\Component\Validator\Constraints\NotBlank()
  *           )
  *       )
  *   )
  *   ->add('age', 'integer');
  *
  * @return null
  */
 protected function buildForm()
 {
     $config_data = BitpayPaymentsConfig::read();
     $this->formBuilder->add("pairingKey", "text", array('label' => Translator::getInstance()->trans("Pairing Key"), 'label_attr' => array('for' => 'pairingKey'), 'data' => isset($config_data['pairingKey']) ? $config_data['pairingKey'] : ""))->add("apiKey", "text", array('label' => Translator::getInstance()->trans("API Key"), 'label_attr' => array('for' => 'apiKey'), 'data' => isset($config_data['apiKey']) ? $config_data['apiKey'] : ""));
 }