Ejemplo n.º 1
0
 /**
  * Creates a Payment.
  *
  * @return Payment
  *
  * @throws \Paytrail\Exception\TooManyProducts
  */
 protected function makePayment()
 {
     $payment = new Payment();
     $payment->configure(array('orderNumber' => 1, 'urlSet' => $this->makeUrlSet(), 'contact' => $this->makeContact(), 'locale' => Payment::LOCALE_ENUS));
     $payment->addProduct($this->makeProduct());
     return $payment;
 }
Ejemplo n.º 2
0
 /**
  * Processes the payment.
  *
  * @param Payment $payment The payment object.
  *
  * @return \Paytrail\Http\Result
  *
  * @throws \Paytrail\Exception\PaymentFailed
  */
 public function processPayment(Payment $payment)
 {
     $response = $this->postRequest('/api-payment/create', $payment->toJson());
     if (!in_array('application/json', $response->getHeader('Content-Type'))) {
         throw new PaymentFailed('Server returned a non-JSON result.');
     }
     $body = json_decode((string) $response->getBody());
     if ($response->getStatusCode() !== 201) {
         throw new PaymentFailed(sprintf('Paytrail request failed: %s (%d)', $body->errorMessage, $body->errorCode));
     }
     $result = new Result();
     $result->configure(array('orderNumber' => $body->orderNumber, 'token' => $body->token, 'url' => $body->url));
     return $result;
 }