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); }
<?php // // Please download the Paymill PHP Wrapper using composer. // If you don't already use Composer, // then you probably should read the installation guide http://getcomposer.org/download/. // //Change the following constants 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(); $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);
/** * @param $subscriptionId * * @return bool|string */ public function cancelSubscription($subscriptionId) { $subscription = new \Paymill\Models\Request\Subscription(); $subscription->setId($subscriptionId)->setRemove(false); try { $response = $this->request->delete($subscription); } catch (\Paymill\Services\PaymillException $e) { s($e->getResponseCode()); s($e->getStatusCode()); s($e->getErrorMessage()); return false; } return $response->getId(); }