Exemple #1
0
 public function payment($token = false, $id = false)
 {
     if (!$this->client_id) {
         throw new LaraMillException('The user has to be connected to a Paymill client to make a payment.', 401);
     }
     $this->currentAction = 'payment';
     $payment = new \Paymill\Models\Request\Payment();
     $payment->setClient($this->client_id);
     if ($id) {
         $payment->setId($id);
     }
     if ($token) {
         $payment->setToken($token);
     }
     return new PaymillGateway($this, $payment);
 }
//
//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);
    } 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);
    }
}