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); }
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> <?php echo $title;