コード例 #1
0
ファイル: SEBTest.php プロジェクト: renekorss/banklink
 /**
  * Set test data.
  */
 public function setUp()
 {
     $this->sellerId = 'id2000';
     $this->sellerName = 'Ülo Pääsuke';
     $this->sellerAccount = '1010342342354345435';
     $this->senderName = 'Toomas Jäär';
     $this->orderId = 100;
     $this->amount = 10.0;
     $this->message = 'First payment';
     $this->language = 'EST';
     $this->currency = 'EUR';
     $this->timezone = 'Europe/Tallinn';
     // From ENV variable
     $this->datetime = getenv('TEST_DATETIME');
     $this->customRequestUrl = 'http://example.com';
     $this->expectedData = array('VK_SERVICE' => '1012', 'VK_VERSION' => '008', 'VK_SND_ID' => $this->sellerId, 'VK_STAMP' => $this->orderId, 'VK_AMOUNT' => $this->amount, 'VK_CURR' => $this->currency, 'VK_REF' => ProtocolHelper::calculateReference($this->orderId), 'VK_MSG' => $this->message, 'VK_RETURN' => $this->customRequestUrl, 'VK_CANCEL' => $this->customRequestUrl, 'VK_LANG' => $this->language, 'VK_MAC' => 'PmAB256IR1FzTKZHNn5LBPso/KyLAhNcTOMq82lhpYn0mXKYtVtpNkolQxyETnTcIn1TcYOmekJEATe86Bz2MRljEQqllkaIl7bNuLCtuBPtAOYWNLmQHoop+5QSiguJEmEV+JJU3w4BApjWcsHA5HYlYze+3L09UO6na0lB/Zs=', 'VK_DATETIME' => $this->datetime, 'VK_ENCODING' => 'UTF-8');
     // Set up banklink
     $this->setUpBanklink();
 }
コード例 #2
0
ファイル: ECommerce.php プロジェクト: renekorss/banklink
 /**
  * Generate MAC string from array of fields.
  *
  * @param array  $data     Array of VK_* fields
  * @param string $encoding Encoding
  *
  * @return string MAC key
  */
 protected function generateSignature(array $data, $encoding = 'UTF-8')
 {
     // Request mac
     $fields = array('ver', 'id', 'ecuno', 'eamount', 'cur', 'datetime', 'feedBackUrl', 'delivery');
     if (isset($data['respcode'])) {
         // Response mac
         $fields = array('ver', 'id', 'ecuno', 'receipt_no', 'eamount', 'cur', 'respcode', 'datetime', 'msgdata', 'actiontext');
         $data['receipt_no'] = ProtocolHelper::mbStrPad($data['receipt_no'], 6, "0", STR_PAD_LEFT, $encoding);
         $data['msgdata'] = ProtocolHelper::mbStrPad($data['respcode'] === self::PAYMENT_RESPONSE_ABORT && strlen($data['msgdata']) == 0 ? ' ' : $data['msgdata'], 40, " ", STR_PAD_RIGHT, $encoding);
         $data['respcode'] = ProtocolHelper::mbStrPad($data['respcode'], 3, "0", STR_PAD_LEFT, $encoding);
         $data['actiontext'] = ProtocolHelper::mbStrPad($data['actiontext'], 40, " ", STR_PAD_RIGHT, $encoding);
     }
     if (isset($data['feedBackUrl'])) {
         $data['feedBackUrl'] = ProtocolHelper::mbStrPad($data['feedBackUrl'], 128);
     }
     // Pad to correct length
     $data['ver'] = ProtocolHelper::mbStrPad($data['ver'], 3, "0", STR_PAD_LEFT, $encoding);
     $data['id'] = ProtocolHelper::mbStrPad($data['id'], 10, " ", STR_PAD_RIGHT, $encoding);
     $data['ecuno'] = ProtocolHelper::mbStrPad($data['ecuno'], 12, "0", STR_PAD_LEFT, $encoding);
     $data['eamount'] = ProtocolHelper::mbStrPad($data['eamount'], 12, "0", STR_PAD_LEFT, $encoding);
     $data['cur'] = ProtocolHelper::mbStrPad($data['cur'], 3, " ", STR_PAD_RIGHT, $encoding);
     $data['datetime'] = ProtocolHelper::mbStrPad($data['datetime'], 14, " ", STR_PAD_RIGHT, $encoding);
     $mac = '';
     foreach ($fields as $key) {
         // Check if field exists
         if (!isset($data[$key]) || $data[$key] === false) {
             throw new \UnexpectedValueException(vsprintf('Field %s must be set to use ECommerce protocol.', array($key)));
         }
         $mac .= $data[$key];
     }
     return $mac;
 }
コード例 #3
0
ファイル: IPizza.php プロジェクト: renekorss/banklink
 /**
  * Get payment object.
  *
  * @param string $orderId  Order ID
  * @param float  $sum      Sum of order
  * @param string $message  Transaction description
  * @param string $encoding Encoding
  * @param string $language Language
  * @param string $currency Currency. Default: EUR
  * @param string $timezone Timezone. Default: Europe/Tallinn
  *
  * @return array Payment request data
  */
 public function getPaymentRequest($orderId, $sum, $message, $encoding = 'UTF-8', $language = 'EST', $currency = 'EUR', $timezone = 'Europe/Tallinn')
 {
     $time = getenv('CI') ? getenv('TEST_DATETIME') : 'now';
     $datetime = new \Datetime($time, new \DateTimeZone($timezone));
     $data = array('VK_SERVICE' => $this->serviceId, 'VK_VERSION' => $this->version, 'VK_SND_ID' => $this->sellerId, 'VK_STAMP' => $orderId, 'VK_AMOUNT' => $sum, 'VK_CURR' => $currency, 'VK_REF' => ProtocolHelper::calculateReference($orderId), 'VK_MSG' => $message, 'VK_RETURN' => $this->requestUrl, 'VK_CANCEL' => $this->requestUrl, 'VK_DATETIME' => $datetime->format('Y-m-d\\TH:i:sO'), 'VK_LANG' => $language);
     if (Services::PAYMENT_REQUEST_1011 === $this->serviceId) {
         $data['VK_NAME'] = $this->sellerName;
         $data['VK_ACC'] = $this->sellerAccount;
     }
     // Generate signature
     $data['VK_MAC'] = $this->getSignature($data, $encoding);
     return $data;
 }
コード例 #4
0
 /**
  * Test exception for too short order id.
  *
  * @expectedException InvalidArgumentException
  */
 public function testReferenceTooShortNotInteger()
 {
     ProtocolHelper::calculateReference('');
 }