Example #1
0
 /**
  * start payment
  * @param OnlineShop_Framework_IPrice $price
  * @param array                       $config
  *
  * @return Zend_Form
  * @throws Exception
  *
  * @see https://pilot.datatrans.biz/showcase/doc/Technical_Implementation_Guide.pdf
  * @see http://pilot.datatrans.biz/showcase/doc/XML_Authorisation.pdf
  */
 public function initPayment(OnlineShop_Framework_IPrice $price, array $config)
 {
     // check params
     $required = ['successUrl' => null, 'errorUrl' => null, 'cancelUrl' => null, 'refno' => null, 'useAlias' => null, 'reqtype' => null, 'language' => null];
     $config = array_intersect_key($config, $required);
     if (count($required) != count($config)) {
         throw new Exception(sprintf('required fields are missing! required: %s', implode(', ', array_keys(array_diff_key($required, $config)))));
     }
     // collect payment data
     $paymentData['amount'] = round($price->getAmount(), 2) * 100;
     $paymentData['currency'] = $price->getCurrency()->getShortName();
     $paymentData['reqtype'] = $config['reqtype'];
     // NOA – Authorisation only (default)
     // CAA – Authorisation and settlement
     // create form
     $form = new Zend_Form();
     $form->setAction($this->endpoint['form']);
     $form->setMethod('post');
     // auth
     $form->addElement('hidden', 'merchantId', ['value' => $this->merchantId]);
     $form->addElement('hidden', 'sign', ['value' => $this->sign]);
     // return urls
     $form->addElement('hidden', 'successUrl', ['value' => $config['successUrl']]);
     $form->addElement('hidden', 'errorUrl', ['value' => $config['errorUrl']]);
     $form->addElement('hidden', 'cancelUrl', ['value' => $config['cancelUrl']]);
     // config
     $form->addElement('hidden', 'language', ['value' => $config['language']]);
     // order data
     $form->addElement('hidden', 'amount', ['value' => $paymentData['amount']]);
     $form->addElement('hidden', 'currency', ['value' => $paymentData['currency']]);
     $form->addElement('hidden', 'refno', ['value' => $config['refno']]);
     $form->addElement('hidden', 'reqtype', ['value' => $paymentData['reqtype']]);
     if ($config['useAlias']) {
         $form->addElement('hidden', 'useAlias', ['value' => 'yes']);
     }
     // add submit button
     $form->addElement('submit', 'submitbutton');
     return $form;
 }
Example #2
0
 /**
  * execute payment
  *
  * @param OnlineShop_Framework_IPrice $price
  * @param string                      $reference
  *
  * @return OnlineShop_Framework_Payment_IStatus
  * @throws Exception
  */
 public function executeDebit(OnlineShop_Framework_IPrice $price = null, $reference = null)
 {
     // TODO: Implement executeDebit() method.
     # https://integration.wirecard.at/doku.php/wcp:toolkit_light:start
     # https://integration.wirecard.at/doku.php/wcs:backend_operations?s[]=deposit
     # https://integration.wirecard.at/doku.php/backend:deposit
     if ($price) {
         // recurPayment
         $request = ['customerId' => $this->customer, 'toolkitPassword' => $this->toolkitPassword, 'command' => 'recurPayment', 'language' => $this->authorizedData['language'], 'requestFingerprint' => '', 'orderDescription' => $reference, 'sourceOrderNumber' => $this->authorizedData['orderNumber'], 'amount' => $price->getAmount(), 'currency' => $price->getCurrency()->getShortName()];
         // add fingerprint
         $request['requestFingerprint'] = $this->computeFingerprint($request['customerId'], $request['toolkitPassword'], $this->secret, $request['command'], $request['language'], $request['sourceOrderNumber'], $request['orderDescription'], $request['amount'], $request['currency']);
     } else {
         // default clearing auth
         $price = new OnlineShop_Framework_Impl_Price($this->authorizedData['amount'], new Zend_Currency($this->authorizedData['currency'], $this->currencyLocale));
         $request = ['customerId' => $this->customer, 'toolkitPassword' => $this->toolkitPassword, 'command' => 'deposit', 'language' => $this->authorizedData['language'], 'requestFingerprint' => '', 'orderNumber' => $this->authorizedData['orderNumber'], 'amount' => $price->getAmount(), 'currency' => $price->getCurrency()->getShortName()];
         // add fingerprint
         $request['requestFingerprint'] = $this->computeFingerprint($request['customerId'], $request['toolkitPassword'], $this->secret, $request['command'], $request['language'], $request['orderNumber'], $request['amount'], $request['currency']);
     }
     // execute request
     $response = $this->serverToServerRequest('https://checkout.wirecard.com/page/toolkit.php', $request);
     // check response
     if ($response['status'] === '0') {
         // Operation successfully done.
         return new OnlineShop_Framework_Impl_Payment_Status($reference, $response['paymentNumber'] ?: $response['orderNumber'], '', OnlineShop_Framework_Payment_IStatus::STATUS_CLEARED, ['qpay_amount' => (string) $price, 'qpay_command' => $request['command'], 'qpay_response' => print_r($response, true)]);
     } else {
         if ($response['errors']) {
             // https://integration.wirecard.at/doku.php/backend:response_parameters
             $error = [];
             for ($e = 1; $e <= $response['errors']; $e++) {
                 $error[] = $response['error_' . $e . '_error_message'];
             }
             return new OnlineShop_Framework_Impl_Payment_Status($reference, $response['paymentNumber'] ?: $response['orderNumber'], implode("\n", $error), OnlineShop_Framework_Payment_IStatus::STATUS_CANCELLED, ['qpay_amount' => (string) $price, 'qpay_command' => $request['command'], 'qpay_response' => print_r($response, true)]);
         } else {
             throw new Exception(print_r($response, true));
         }
     }
 }
Example #3
0
 /**
  * modify price
  *
  * @param OnlineShop_Framework_IPrice $currentSubTotal
  * @param OnlineShop_Framework_ICart  $cart
  *
  * @return OnlineShop_Framework_IPrice
  */
 public function modify(OnlineShop_Framework_IPrice $currentSubTotal, OnlineShop_Framework_ICart $cart)
 {
     if ($this->getAmount() != 0) {
         return new OnlineShop_Framework_Impl_ModificatedPrice($this->getAmount(), $currentSubTotal->getCurrency(), false, $this->rule->getLabel());
     }
 }
Example #4
0
 /**
  * @param OnlineShop_Framework_IPrice $price
  *
  * @return stdClass
  */
 protected function createPaymentDetails(OnlineShop_Framework_IPrice $price)
 {
     // create order total
     $paymentDetails = new stdClass();
     $paymentDetails->OrderTotal = new stdClass();
     $paymentDetails->OrderTotal->_ = $price->getAmount();
     $paymentDetails->OrderTotal->currencyID = $price->getCurrency()->getShortName();
     //        // add article
     //        $itemTotal = 0;
     //        $paymentDetails->PaymentDetailsItem = array();
     //        foreach($this->cart->getItems() as $item)
     //        {
     //            $article = new stdClass();
     //            $article->Name = $item->getProduct()->getOSName();
     //            $article->Description = $item->getComment();
     //            $article->Number = $item->getProduct()->getOSProductNumber();
     //            $article->Quantity = $item->getCount();
     //            $article->Amount = new stdClass();
     //            $article->Amount->_ = $item->getPrice()->getAmount();
     //            $article->Amount->currencyID = $currency;
     //
     //            $paymentDetails->PaymentDetailsItem[] = $article;
     //            $itemTotal += $item->getPrice()->getAmount();
     //        }
     //
     //
     //        // add modificators
     //        foreach($priceCalculator->getPriceModifications() as $name => $modification)
     //        {
     //            if($modification instanceof OnlineShop_Framework_IModificatedPrice && $name == 'shipping')
     //            {
     //                // add shipping charge
     //                $paymentDetails->ShippingTotal = new stdClass();
     //                $paymentDetails->ShippingTotal->_ = $modification->getAmount();
     //                $paymentDetails->ShippingTotal->currencyID = $currency;
     //            }
     //            else if($modification instanceof OnlineShop_Framework_IModificatedPrice && $modification->getAmount() !== 0)
     //            {
     //                // add discount line
     //                $article = new stdClass();
     //                $article->Name = $modification->getDescription();
     //                $article->Quantity = 1;
     //                $article->PromoCode = $modification->getDescription();
     //                $article->Amount = new stdClass();
     //                $article->Amount->_ = $modification->getAmount();
     //                $article->Amount->currencyID = $currency;
     //                $paymentDetails->PaymentDetailsItem[] = $article;
     //
     //                $itemTotal += $modification->getAmount();;
     //            }
     //        }
     //
     //
     //        // create item total
     //        $paymentDetails->ItemTotal = new stdClass();
     //        $paymentDetails->ItemTotal->_ = $itemTotal;
     //        $paymentDetails->ItemTotal->currencyID = $currency;
     return $paymentDetails;
 }