Ejemplo n.º 1
0
 public static function start($options = array())
 {
     $api = new Api\Start();
     if (isset($options['amount'])) {
         $api->setAmount(round($options['amount'] * 100));
     }
     if (isset($options['currency'])) {
         $api->setCurrency($options['currency']);
     }
     if (isset($options['returnUrl'])) {
         $api->setFinishUrl($options['returnUrl']);
     }
     if (isset($options['exchangeUrl'])) {
         $api->setExchangeUrl($options['exchangeUrl']);
     }
     if (isset($options['paymentMethod']) && !empty($options['paymentMethod'])) {
         $api->setPaymentOptionId($options['paymentMethod']);
     }
     if (isset($options['bank']) && !empty($options['bank'])) {
         $api->setPaymentOptionSubId($options['bank']);
     }
     if (isset($options['description']) && !empty($options['description'])) {
         $api->setDescription($options['description']);
     }
     if (isset($options['testmode']) && $options['testmode'] == 1) {
         $api->setTestMode(true);
     }
     if (isset($options['extra1'])) {
         $api->setExtra1($options['extra1']);
     }
     if (isset($options['extra2'])) {
         $api->setExtra2($options['extra2']);
     }
     if (isset($options['extra3'])) {
         $api->setExtra3($options['extra3']);
     }
     if (isset($options['ipaddress'])) {
         $api->setIpAddress($options['ipaddress']);
     }
     if (isset($options['products'])) {
         foreach ($options['products'] as $product) {
             $taxClass = Helper::calculateTaxClass($product['price'], $product['tax']);
             $api->addProduct($product['id'], $product['name'], round($product['price'] * 100), $product['qty'], $taxClass);
         }
     }
     $enduser = array();
     if (isset($options['enduser'])) {
         $enduser = $options['enduser'];
     }
     if (isset($options['language'])) {
         $enduser['language'] = $options['language'];
     }
     if (isset($options['address'])) {
         $address = array();
         if (isset($options['address']['streetName'])) {
             $address['streetName'] = $options['address']['streetName'];
         }
         if (isset($options['address']['houseNumber'])) {
             $address['streetNumber'] = $options['address']['houseNumber'];
         }
         if (isset($options['address']['zipCode'])) {
             $address['zipCode'] = $options['address']['zipCode'];
         }
         if (isset($options['address']['city'])) {
             $address['city'] = $options['address']['city'];
         }
         if (isset($options['address']['country'])) {
             $address['countryCode'] = $options['address']['country'];
         }
         $enduser['address'] = $address;
     }
     if (isset($options['invoiceAddress'])) {
         $invoiceAddress = array();
         if (isset($options['invoiceAddress']['initials'])) {
             $invoiceAddress['initials'] = $options['invoiceAddress']['initials'];
         }
         if (isset($options['invoiceAddress']['lastName'])) {
             $invoiceAddress['lastName'] = $options['invoiceAddress']['lastName'];
         }
         if (isset($options['invoiceAddress']['streetName'])) {
             $invoiceAddress['streetName'] = $options['invoiceAddress']['streetName'];
         }
         if (isset($options['invoiceAddress']['houseNumber'])) {
             $invoiceAddress['streetNumber'] = $options['invoiceAddress']['houseNumber'];
         }
         if (isset($options['invoiceAddress']['zipCode'])) {
             $invoiceAddress['zipCode'] = $options['invoiceAddress']['zipCode'];
         }
         if (isset($options['invoiceAddress']['city'])) {
             $invoiceAddress['city'] = $options['invoiceAddress']['city'];
         }
         if (isset($options['invoiceAddress']['country'])) {
             $invoiceAddress['countryCode'] = $options['invoiceAddress']['country'];
         }
         $enduser['invoiceAddress'] = $invoiceAddress;
     }
     if (!empty($enduser)) {
         $api->setEnduser($enduser);
     }
     $result = $api->doRequest();
     return new Result\Start($result);
 }
Ejemplo n.º 2
0
 /**
  * Start a new transaction
  *
  * @param array|null $options
  * @return Result\Start
  * @throws Error\Error
  */
 public static function start($options = array())
 {
     $api = new Api\Start();
     if (isset($options['amount'])) {
         $api->setAmount(round($options['amount'] * 100));
     }
     if (isset($options['currency'])) {
         $api->setCurrency($options['currency']);
     }
     if (isset($options['expireDate'])) {
         if (is_string($options['expireDate'])) {
             $options['expireDate'] = new \DateTime($options['expireDate']);
         }
         $api->setExpireDate($options['expireDate']);
     }
     if (isset($options['returnUrl'])) {
         $api->setFinishUrl($options['returnUrl']);
     }
     if (isset($options['exchangeUrl'])) {
         $api->setExchangeUrl($options['exchangeUrl']);
     }
     if (isset($options['paymentMethod']) && !empty($options['paymentMethod'])) {
         $api->setPaymentOptionId($options['paymentMethod']);
     }
     if (isset($options['bank']) && !empty($options['bank'])) {
         $api->setPaymentOptionSubId($options['bank']);
     }
     if (isset($options['description']) && !empty($options['description'])) {
         $api->setDescription($options['description']);
     }
     if (isset($options['testmode']) && $options['testmode'] == 1) {
         $api->setTestMode(true);
     }
     if (isset($options['extra1'])) {
         $api->setExtra1($options['extra1']);
     }
     if (isset($options['extra2'])) {
         $api->setExtra2($options['extra2']);
     }
     if (isset($options['extra3'])) {
         $api->setExtra3($options['extra3']);
     }
     if (isset($options['ipaddress'])) {
         $api->setIpAddress($options['ipaddress']);
     }
     if (isset($options['invoiceDate'])) {
         if (is_string($options['invoiceDate'])) {
             $options['invoiceDate'] = new \DateTime($options['invoiceDate']);
         }
         $api->setInvoiceDate($options['invoiceDate']);
     }
     if (isset($options['deliveryDate'])) {
         if (is_string($options['deliveryDate'])) {
             $options['deliveryDate'] = new \DateTime($options['deliveryDate']);
         }
         $api->setDeliveryDate($options['deliveryDate']);
     }
     if (isset($options['products'])) {
         foreach ($options['products'] as $product) {
             $taxClass = Helper::calculateTaxClass($product['price'], $product['tax']);
             $taxPercentage = null;
             if (isset($product['vatPercentage']) && is_numeric($product['vatPercentage'])) {
                 $taxPercentage = round($product['vatPercentage'], 2);
                 $taxClass = Helper::calculateTaxClass(100 + $taxPercentage, $taxPercentage);
             } else {
                 $taxPercentage = round(Helper::calculateTaxPercentage($product['price'], $product['tax']));
             }
             if (!isset($product['type'])) {
                 $product['type'] = self::PRODUCT_TYPE_ARTICLE;
             }
             $api->addProduct($product['id'], $product['name'], $product['type'], round($product['price'] * 100), $product['qty'], $taxClass, $taxPercentage);
         }
     }
     $enduser = array();
     if (isset($options['enduser'])) {
         if (isset($options['enduser']['birthDate'])) {
             $options['enduser']['birthDate'] = new \DateTime($options['enduser']['birthDate']);
         }
         $enduser = $options['enduser'];
     }
     if (isset($options['language'])) {
         $enduser['language'] = $options['language'];
     }
     if (isset($options['address'])) {
         $address = array();
         if (isset($options['address']['streetName'])) {
             $address['streetName'] = $options['address']['streetName'];
         }
         if (isset($options['address']['houseNumber'])) {
             $address['streetNumber'] = $options['address']['houseNumber'];
         }
         if (isset($options['address']['houseNumberExtension'])) {
             $address['streetNumberExtension'] = $options['address']['houseNumberExtension'];
         }
         if (isset($options['address']['zipCode'])) {
             $address['zipCode'] = $options['address']['zipCode'];
         }
         if (isset($options['address']['city'])) {
             $address['city'] = $options['address']['city'];
         }
         if (isset($options['address']['country'])) {
             $address['countryCode'] = $options['address']['country'];
         }
         $enduser['address'] = $address;
     }
     if (isset($options['invoiceAddress'])) {
         $invoiceAddress = array();
         if (isset($options['invoiceAddress']['initials'])) {
             $invoiceAddress['initials'] = $options['invoiceAddress']['initials'];
         }
         if (isset($options['invoiceAddress']['lastName'])) {
             $invoiceAddress['lastName'] = $options['invoiceAddress']['lastName'];
         }
         if (isset($options['invoiceAddress']['streetName'])) {
             $invoiceAddress['streetName'] = $options['invoiceAddress']['streetName'];
         }
         if (isset($options['invoiceAddress']['houseNumber'])) {
             $invoiceAddress['streetNumber'] = $options['invoiceAddress']['houseNumber'];
         }
         if (isset($options['invoiceAddress']['houseNumberExtension'])) {
             $invoiceAddress['streetNumberExtension'] = $options['invoiceAddress']['houseNumberExtension'];
         }
         if (isset($options['invoiceAddress']['zipCode'])) {
             $invoiceAddress['zipCode'] = $options['invoiceAddress']['zipCode'];
         }
         if (isset($options['invoiceAddress']['city'])) {
             $invoiceAddress['city'] = $options['invoiceAddress']['city'];
         }
         if (isset($options['invoiceAddress']['country'])) {
             $invoiceAddress['countryCode'] = $options['invoiceAddress']['country'];
         }
         if (isset($options['invoiceAddress']['gender'])) {
             $invoiceAddress['gender'] = $options['invoiceAddress']['gender'];
         }
         $enduser['invoiceAddress'] = $invoiceAddress;
     }
     if (!empty($enduser)) {
         $api->setEnduser($enduser);
     }
     if (isset($options['transferType'])) {
         $api->setTransferType($options['transferType']);
     }
     if (isset($options['transferValue'])) {
         $api->setTransferValue($options['transferValue']);
     }
     $result = $api->doRequest();
     return new Result\Start($result);
 }