Beispiel #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);
 }
 /**
  * @param        $token
  * @param        $amount
  * @param        $subscriptionName
  * @param        $clientId
  * @param string $currency
  * @param string $interval
  * @param null   $paymentId
  *
  * @return bool|SubscriptionPaymentResult
  */
 public function createSubscription($token, $amount, $subscriptionName, $clientId, $currency = 'EUR', $paymentId = null, $interval = '1 month', $trial = '1 week')
 {
     if (!$paymentId) {
         $payment = new \Paymill\Models\Request\Payment();
         $payment->setToken($token)->setClient($clientId);
         try {
             $response = $this->request->create($payment);
         } catch (\Paymill\Services\PaymillException $e) {
             s($e->getResponseCode());
             s($e->getStatusCode());
             s($e->getErrorMessage());
             return false;
         }
         $paymentId = $response->getId();
     }
     $subscription = new \Paymill\Models\Request\Subscription();
     $subscription->setClient($clientId);
     $subscription->setAmount($amount * 100);
     $subscription->setCurrency($currency);
     $subscription->setInterval($interval);
     $subscription->setPayment($paymentId);
     $subscription->setName($subscriptionName);
     $subscription->setPeriodOfValidity('10 YEAR');
     //        $subscription->setStartAt(strtotime(gmdate('Y-m-d 00:00:00', strtotime('+1 day'))));
     $subscription->setStartAt(time() + 3600);
     //        $subscription->setStartAt(time() + strtotime($trial)); // trial mode
     try {
         /** @var Subscription $response */
         $response = $this->request->create($subscription);
     } catch (\Paymill\Services\PaymillException $e) {
         s($e->getResponseCode());
         s($e->getStatusCode());
         s($e->getErrorMessage());
         return false;
     }
     return new SubscriptionPaymentResult(['subscription_id' => $response->getId(), 'payment_id' => $response->getPayment()->getId()]);
 }
 function gdlr_hotel_paymill_payment()
 {
     global $hotel_option;
     $ret = array();
     if (!empty($_POST['token']) && !empty($_POST['invoice'])) {
         global $wpdb;
         $temp_sql = "SELECT * FROM " . $wpdb->prefix . "gdlr_hotel_payment ";
         $temp_sql .= "WHERE id = " . $_POST['invoice'];
         $result = $wpdb->get_row($temp_sql);
         $contact_info = unserialize($result->contact_info);
         $apiKey = $hotel_option['paymill-private-key'];
         $request = new Paymill\Request($apiKey);
         $payment = new Paymill\Models\Request\Payment();
         $payment->setToken($_POST['token']);
         try {
             $response = $request->create($payment);
             $paymentId = $response->getId();
             $transaction = new Paymill\Models\Request\Transaction();
             $transaction->setAmount(floatval($result->pay_amount) * 100)->setCurrency($hotel_option['paymill-currency-code'])->setPayment($paymentId)->setDescription($payment_info['email']);
             $response = $request->create($transaction);
             $wpdb->update($wpdb->prefix . 'gdlr_hotel_payment', array('payment_status' => 'paid', 'payment_info' => serialize($response), 'payment_date' => date('Y-m-d H:i:s')), array('id' => $_POST['invoice']), array('%s', '%s', '%s'), array('%d'));
             $data = unserialize($result->booking_data);
             $mail_content = gdlr_hotel_mail_content($contact_info, $data, $response, array('total_price' => $result->total_price, 'pay_amount' => $result->pay_amount, 'booking_code' => $result->customer_code));
             gdlr_hotel_mail($contact_info['email'], __('Thank you for booking the room with us.', 'gdlr-hotel'), $mail_content);
             gdlr_hotel_mail($hotel_option['recipient-mail'], __('New room booking received', 'gdlr-hotel'), $mail_content);
             $ret['status'] = 'success';
             $ret['message'] = __('Payment complete', 'gdlr-hotel');
             $ret['content'] = gdlr_booking_complete_message();
         } catch (PaymillException $e) {
             $ret['status'] = 'failed';
             $ret['message'] = $e->getErrorMessage();
         }
     } else {
         $ret['status'] = 'failed';
         $ret['message'] = __('Failed to proceed, please try again.', 'gdlr-hotel');
     }
     die(json_encode($ret));
 }
        <meta http-equiv="content-type"
              content="text/html; charset=utf-8"/>
       <?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);
function gdlr_lms_paymill_payment()
{
    global $gdlr_lms_option;
    $ret = array();
    if (!empty($_POST['token']) && !empty($_POST['invoice'])) {
        global $wpdb;
        $temp_sql = "SELECT * FROM " . $wpdb->prefix . "gdlrpayment ";
        $temp_sql .= "WHERE id = " . $_POST['invoice'];
        $result = $wpdb->get_row($temp_sql);
        $payment_info = unserialize($result->payment_info);
        $apiKey = $gdlr_lms_option['paymill-private-key'];
        $request = new Paymill\Request($apiKey);
        $payment = new Paymill\Models\Request\Payment();
        $payment->setToken($_POST['token']);
        try {
            $response = $request->create($payment);
            $paymentId = $response->getId();
            $transaction = new Paymill\Models\Request\Transaction();
            $transaction->setAmount(floatval($result->pay_amount) * 100)->setCurrency($gdlr_lms_option['paymill-currency-code'])->setPayment($paymentId)->setDescription($payment_info['email']);
            $response = $request->create($transaction);
            $wpdb->update($wpdb->prefix . 'gdlrpayment', array('payment_status' => 'paid', 'attachment' => serialize($response), 'payment_date' => date('Y-m-d H:i:s')), array('id' => $_POST['invoice']), array('%s', '%s', '%s'), array('%d'));
            gdlr_lms_mail($payment_info['email'], __('Stripe Payment Received', 'gdlr-lms'), __('Your verification code is', 'gdlr-lms') . ' ' . $payment_info['code']);
            $ret['status'] = 'success';
            $ret['message'] = __('Payment complete, redirecting to the course page.', 'gdlr-lms');
            $ret['redirect'] = get_permalink($result->course_id);
            $ret['data'] = $result;
        } catch (PaymillException $e) {
            $ret['status'] = 'failed';
            $ret['message'] = $e->getErrorMessage();
        }
    } else {
        $ret['status'] = 'failed';
        $ret['message'] = __('Failed to retrieve the course, please made the payment from course page again.', 'gdlr-lms');
    }
    die(json_encode($ret));
}