예제 #1
0
 public static function processRequest($token, $arrOrder)
 {
     global $_CONFIG;
     if (empty($token)) {
         return array('status' => 'error', 'message' => 'invalid token');
     }
     $testMode = intval(\Cx\Core\Setting\Controller\Setting::getValue('paymill_use_test_account', 'Shop')) == 0;
     $apiKey = $testMode ? \Cx\Core\Setting\Controller\Setting::getValue('paymill_test_private_key', 'Shop') : \Cx\Core\Setting\Controller\Setting::getValue('paymill_live_private_key', 'Shop');
     if ($token) {
         try {
             $request = new Paymill\Request($apiKey);
             $transaction = new Paymill\Models\Request\Transaction();
             $transaction->setAmount($arrOrder['amount'])->setCurrency($arrOrder['currency'])->setToken($token)->setDescription($arrOrder['note'])->setSource('contrexx_' . $_CONFIG['coreCmsVersion']);
             DBG::log("Transactoin created with token:" . $token);
             $response = $request->create($transaction);
             $paymentId = $response->getId();
             DBG::log("Payment ID" . $paymentId);
             return array('status' => 'success', 'payment_id' => $paymentId);
         } catch (\Paymill\Services\PaymillException $e) {
             //Do something with the error informations below
             return array('status' => 'error', 'response_code' => $e->getResponseCode(), 'status_code' => $e->getStatusCode(), 'message' => $e->getErrorMessage());
         }
     }
 }
예제 #2
0
// 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);
    } 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);
    }
 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));
 }
예제 #4
0
<?php

require '../vendor/paymill/paymill/autoload.php';
// Private Key
$apiKey = "";
$request = new Paymill\Request($apiKey);
$transaction = new Paymill\Models\Request\Transaction();
$transaction->setAmount($_POST['amount'])->setCurrency($_POST['currency'])->setToken($_POST['token'])->setDescription($_POST['description']);
try {
    $response = $request->create($transaction);
    include "guide_payment_end.php";
} catch (\Paymill\Services\PaymillException $e) {
    echo "An error occured while processing the transaction: ";
    echo $e->getErrorMessage();
}
예제 #5
0
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));
}
예제 #6
0
 /**
  * Processes the payment
  * This method process only real time (simple) payments
  *
  * @return  string   unknown_type.
  *
  * @return  string
  *
  * @access protected
  * */
 public function _process()
 {
     if (!JRequest::checkToken()) {
         return $this->_renderHtml(JText::_('J2STORE_PAYMILL_INVALID_TOKEN'));
     }
     $app = JFactory::getApplication();
     $data = $app->input->getArray($_POST);
     $json = array();
     $errors = array();
     // Get order information
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_j2store/tables');
     $order = JTable::getInstance('Orders', 'Table');
     $order->load($data['orderpayment_id']);
     // Check for exisiting things
     if (empty($order->order_id)) {
         $json['error'] = JText::_('J2STORE_PAYMILL_INVALID_ORDER');
     }
     if (empty($data['token'])) {
         $json['error'] = JText::_('J2STORE_PAYMILL_TOKEN_MISSING');
     }
     if (!$json) {
         $currency_values = $this->getCurrency($order);
         $amount = $this->getAmount($order->orderpayment_amount, $currency_values['currency_code'], $currency_values['currency_value'], $currency_values['convert']) * 100;
         try {
             require JPath::clean(dirname(__FILE__) . "/library/autoload.php");
             $request = new Paymill\Request($this->private_key);
             $request->setSource('J2Store');
             $transaction = new Paymill\Models\Request\Transaction();
             $transaction->setAmount($amount)->setCurrency($currency_values['currency_code'])->setToken($data['token'])->setDescription(JText::_('J2STORE_PAYMILL_ORDER_DESCRIPTION'));
             $response = $request->create($transaction);
             $paymentId = $response->getId();
             $responseCode = $response->getResponseCode();
             $raw = $request->getLastResponse();
             $rawResponse = $raw['body']['data'];
             $transaction_details = $this->_getFormattedTransactionDetails($rawResponse);
             $order->transaction_id = $paymentId;
             $order->transaction_details = $transaction_details;
             $order->transaction_status = $rawResponse['status'];
             $sendEmail = false;
             if (isset($rawResponse['error'])) {
                 $order->order_state_id = 3;
                 $order->order_state = JText::_('J2STORE_DECLINED');
                 $errors[] = $resp['error'];
             } elseif (strtolower($rawResponse['status']) == 'closed') {
                 $order->order_state_id = 1;
                 $order->order_state = JText::_('J2STORE_COMPLETED');
                 $sendEmail = true;
             } elseif (strtolower($rawResponse['status']) == 'pending') {
                 $order->order_state_id = 4;
                 $order->order_state = JText::_('J2STORE_PENDING');
             } elseif (strtolower($rawResponse['status']) == 'failed') {
                 $order->order_state_id = 3;
                 $order->order_state = JText::_('J2STORE_FAILED');
             } else {
                 $order->order_state_id = 3;
                 $order->order_state = JText::_('J2STORE_FAILED');
                 $errors[] = JText::_("J2STORE_PAYMILL_ERROR_PROCESSING_PAYMENT");
             }
             // save the orderpayment
             if (!$order->save()) {
                 $errors[] = $order->getError();
             }
         } catch (PaymillException $e) {
             //Do something with the error informations below
             $e->getResponseCode();
             $e->getStatusCode();
             $errMsg = $e->getErrorMessage();
             $errors[] = $errMsg;
             $this->_log($errMsg, 'payment response error');
         }
         if (empty($errors)) {
             // remove items from cart
             J2StoreHelperCart::removeOrderItems($order->id);
             if ($sendEmail) {
                 //let us inform the user that the payment is successful
                 J2StoreOrdersHelper::sendUserEmail($order->user_id, $order->order_id, $order->order_state, $order->order_state, $order->order_state_id);
             }
             $json['success'] = JText::_($this->params->get('onafterpayment', ''));
             $json['redirect'] = JRoute::_('index.php?option=com_j2store&view=checkout&task=confirmPayment&orderpayment_type=' . $this->_element . '&paction=display');
         }
         if (count($errors)) {
             $json['error'] = implode("\n", $errors);
         }
     }
     return $json;
 }
예제 #7
0
 /**
  * Allow admin to create new offers.
  *
  * @param CreateNewOfferRequest $request
  */
 public function create(CreateNewOfferRequest $request)
 {
     // Create new paymill request
     $paymillRequest = new \Paymill\Request(env('PAYMILL_API_KEY'));
     $currency = 'EUR';
     $interval = '1 MONTH';
     // Create new offer
     $paymillOffer = new \Paymill\Models\Request\Offer();
     $paymillOffer->setAmount($request->get('offer_amount'))->setCurrency($currency)->setInterval($interval)->setName($request->get('offer_name'));
     $response = $paymillRequest->create($paymillOffer);
     $promoCode = $request->get('promo_code');
     $enableOffer = $request->get('enable_offer');
     $useOnSignUp = $request->get('use_on_sign_up');
     // If this offer will be used on sign up make sure it is the only one
     if ($useOnSignUp) {
         Offer::where('use_on_sign_up', true)->update(['use_on_sign_up' => false]);
         $promoCode = '';
         $enableOffer = false;
     }
     // An enabled offer can not be used on sign up
     if ($enableOffer) {
         $useOnSignUp = false;
     }
     // Save in database
     Offer::create(['paymill_offer_id' => $response->getId(), 'name' => $request->get('offer_name'), 'amount' => $request->get('offer_amount'), 'interval' => $interval, 'currency' => $currency, 'promo_code' => $promoCode, 'use_on_sign_up' => (bool) $useOnSignUp, 'disabled' => !(bool) $enableOffer]);
     // Return response
     $ajaxResponse = new AjaxResponse();
     $ajaxResponse->setSuccessMessage(trans('offers.offer_created'));
     return response($ajaxResponse->get())->header('Content-Type', 'application/json');
 }
예제 #8
0
// 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();
    $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);
    }
}