function testConstructorShouldNotAppendRandomIdToTransactionId()
 {
     Config::setIdSeparator(false);
     $p = new PaymentRequest($this->fixture('wpf_payment_request_simple.json'));
     $p->validate();
     $this->assertPattern('/^wev238f328nc$/', $p->transaction_id);
 }
 function testValidatesThrowsExeption()
 {
     $data = array('type' => 'MobilePayment', 'amount' => -2000, 'currency' => 'WRONG', 'transaction_id' => 'test-1234', 'usage' => 'the Usage Text', 'notification_url' => 'https://my-server.com/hypercharge/payment-notification.php');
     $request = new PaymentRequest($data);
     try {
         $request->validate();
         $this->fail('Exception expected!');
     } catch (Errors\ValidationError $exe) {
         $this->assertEqual($exe->status_code, 50);
         $this->assertPattern('/^2 validation errors/', $exe->getMessage());
         $this->assertEqual('2 affected properties: payment.amount, payment.currency', $exe->technical_message);
         $this->assertEqual('payment.amount', $exe->errors[0]['property']);
         $this->assertEqual('must have a minimum value of 1', $exe->errors[0]['message']);
         $this->assertEqual('payment.currency', $exe->errors[1]['property']);
         $this->assertPattern('/^does not have a value in the enumeration Array/', $exe->errors[1]['message']);
         return;
     }
     $this->fail('Errors\\ValidationError expected!');
 }
Exemplo n.º 3
0
 /**
  *
  */
 public function prepareRequest(PaymentRequest $paymentRequest)
 {
     // Make sure we have a valid PaymentRequest
     if ($paymentRequest->validate()) {
         // Prepare the data so we can create a seal
         $data = ['amount' => $paymentRequest->amount, 'automaticResponseUrl' => $paymentRequest->automaticResponseUrl, 'captureDay' => $paymentRequest->captureDay, 'captureMode' => $paymentRequest->captureMode, 'currencyCode' => empty($paymentRequest->currencyCode) ? $this->currencyCode : $paymentRequest->currencyCode, 'customerLanguage' => empty($paymentRequest->customerLanguage) ? $this->customerLanguage : $paymentRequest->customerLanguage, 'expirationDate' => $paymentRequest->expirationDate, 'keyVersion' => $this->keyVersion, 'merchantId' => $this->merchantId, 'normalReturnUrl' => $paymentRequest->normalReturnUrl, 'orderId' => $paymentRequest->orderId, 'paymentMeanBrandList' => empty($paymentRequest->paymentMeanBrandList) ? $this->paymentMeanBrandList : $paymentRequest->paymentMeanBrandList, 'transactionReference' => $paymentRequest->transactionReference];
         $this->dataField = [];
         foreach ($data as $key => $value) {
             if (!empty($value)) {
                 $this->dataField[] = "{$key}={$value}";
             }
         }
         $this->dataField = implode('|', $this->dataField);
         $this->seal = hash('sha256', $this->dataField . $this->secretKey);
     } else {
         throw new \yii\base\InvalidConfigException('Invalid config for PaymentRequest object, check requirements');
     }
 }