/**
  * @param        $token
  * @param        $amount
  * @param        $transactionDetails
  * @param null   $clientId
  * @param string $currency
  *
  * @return bool|OneTimePaymentResult
  */
 public function makeOneTimePayment($token, $amount, $transactionDetails, $clientId = null, $currency = 'EUR', $paymentId = null)
 {
     $transaction = new \Paymill\Models\Request\Transaction();
     $transaction->setAmount($amount * 100)->setCurrency($currency)->setDescription($transactionDetails);
     if ($paymentId) {
         $transaction->setPayment($paymentId);
     } else {
         $transaction->setToken($token);
     }
     if ($clientId) {
         $transaction->setClient($clientId);
     }
     try {
         /** @var Transaction $response */
         $response = $this->request->create($transaction);
     } catch (\Paymill\Services\PaymillException $e) {
         s($e->getResponseCode());
         s($e->getStatusCode());
         s($e->getErrorMessage());
         return false;
     }
     return new OneTimePaymentResult(['transaction_id' => $response->getId(), 'payment_id' => $response->getPayment()->getId()]);
 }
Beispiel #2
0
 public function transaction($payment = false, $id = false, $amount = false, $currency = 'GBP')
 {
     if (!$this->client_id) {
         throw new LaraMillException('The user has to be connected to a Paymill client to make a payment.', 401);
     }
     $transaction = new \Paymill\Models\Request\Transaction();
     $transaction->setClient($this->client_id);
     if ($id) {
         $transaction->setId($id);
     } else {
         // Get payment
         if ($payment) {
             $payment = $this->payment(false, $payment)->details();
         } else {
             $payments = $this->payment()->all();
             if (empty($payments)) {
                 throw new LaraMillException('The user has to have a payment to create a transaction.', 401);
             }
             $payment = $payments[count($payments) - 1];
         }
         $transaction->setPayment($payment->getId());
         $transaction->setAmount($amount);
         $transaction->setCurrency($currency);
     }
     $this->currentAction = 'transaction';
     return new PaymillGateway($this, $transaction);
 }