public function subscription($plan = false, $payment_interval = false, $payment = false) { if (!$this->client_id) { throw new LaraMillException('The user has to be connected to a Paymill client to make a payment.', 401); } $subscription = new \Paymill\Models\Request\Subscription(); $subscription->setClient($this->client_id); if ($plan and $payment_interval) { // Get offer id $offers = \Config::get('billing::offers'); if (!$offers or (!isset($offers[$plan]) or !isset($offers[$plan][$payment_interval]))) { throw new LaraMillException('No offers found.', 412); } $offer = $offers[$plan][$payment_interval]; $subscription->setOffer($offer); } // Get payment if ($payment) { $payment = $this->payment($payment)->details(); } else { $payments = $this->payment()->all(); $payment = $payments[count($payments) - 1]; } $subscription->setPayment($payment->getId()); $this->currentAction = 'subscription'; return new PaymillGateway($this, $subscription); }
$client = new Paymill\Models\Request\Client(); $payment = new Paymill\Models\Request\Payment(); $offer = new Paymill\Models\Request\Offer(); $subscription = new Paymill\Models\Request\Subscription(); try { $client->setEmail(CUSTOMER_EMAIL); $client->setDescription('This is a Testuser.'); $clientResponse = $service->create($client); $payment->setClient($clientResponse->getId()); $payment->setToken($_POST['paymillToken']); $paymentResponse = $service->create($payment); $offer->setAmount($_POST['amount'])->setCurrency($_POST['currency'])->setInterval($_POST['interval'])->setName($_POST['offer-name']); $offerResponse = $service->create($offer); $subscription->setClient($clientResponse->getId()); $subscription->setPayment($paymentResponse->getId()); $subscription->setOffer($offerResponse->getId()); $subscriptionResponse = $service->create($subscription); $title = "<h1>We appreciate your order!</h1>"; $result = print_r($subscriptionResponse, 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; ?>