/** * @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()]); }
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); }
define('PAYMILL_API_KEY', 'YOUR_API_KEY'); define('CUSTOMER_EMAIL', 'SOME_TEST_EMAIL'); require 'vendor/autoload.php'; if (isset($_POST['paymillToken'])) { $service = new Paymill\Request(PAYMILL_API_KEY); $client = new Paymill\Models\Request\Client(); $payment = new Paymill\Models\Request\Payment(); $transaction = new \Paymill\Models\Request\Transaction(); try { $client->setEmail(CUSTOMER_EMAIL); $client->setDescription('This is a Testuser.'); $clientResponse = $service->create($client); $payment->setToken($_POST['paymillToken']); $payment->setClient($clientResponse->getId()); $paymentResponse = $service->create($payment); $transaction->setPayment($paymentResponse->getId()); $transaction->setAmount($_POST['amount'] * 100); $transaction->setCurrency($_POST['currency']); $transaction->setDescription('Test Transaction'); $transactionResponse = $service->create($transaction); $title = "<h1>We appreciate your purchase!</h1>"; $result = print_r($transactionResponse, true); } catch (\Paymill\Services\PaymillException $e) { $title = "<h1>An error has occoured!</h1>"; $result = print_r($e->getResponseCode(), true) . " <br />" . print_r($e->getResponseCode(), true) . " <br />" . print_r($e->getErrorMessage(), true); } } ?> </head> <body> <div>