/**
  * {@inheritDoc}
  *
  * @param Transaction $request
  */
 public function execute($request)
 {
     RequestNotSupportedException::assertSupports($this, $request);
     $details = ArrayObject::ensureArrayObject($request->getModel());
     if (!isset($details['token']) || empty($details['token'])) {
         throw new LogicException('The token has to be set.');
     }
     try {
         $transaction = new \Paymill\Models\Request\Transaction();
         $transaction->setAmount($details['amount'])->setCurrency($details['currency'])->setDescription($details['description'])->setToken($details['token']);
         $requestPaymill = new Request($this->api->getPrivateKey());
         $requestPaymill->create($transaction);
         $responsePaymill = $requestPaymill->getLastResponse();
         $details['http_status_code'] = 200;
         $details['transaction'] = $responsePaymill['body']['data'];
     } catch (PaymillException $e) {
         $details['http_status_code'] = $e->getStatusCode();
         $details['error'] = $e->getResponseCode();
         $details['errorMessage'] = $e->getMessage();
         $details['errorResponse'] = $e->getRawObject();
     }
     $request->setModel($details);
 }
 /**
  * @param        $token
  * @param        $amount
  * @param        $transactionDetails
  * @param null   $clientId
  * @param string $currency
  *
  * @return bool|OneTimePaymentResult
  */
 public function makeOneTimePayment($token, $amount, $transactionDetails, $clientId = null, $currency = 'EUR', $paymentId = null)
 {
     $transaction = new \Paymill\Models\Request\Transaction();
     $transaction->setAmount($amount * 100)->setCurrency($currency)->setDescription($transactionDetails);
     if ($paymentId) {
         $transaction->setPayment($paymentId);
     } else {
         $transaction->setToken($token);
     }
     if ($clientId) {
         $transaction->setClient($clientId);
     }
     try {
         /** @var Transaction $response */
         $response = $this->request->create($transaction);
     } catch (\Paymill\Services\PaymillException $e) {
         s($e->getResponseCode());
         s($e->getStatusCode());
         s($e->getErrorMessage());
         return false;
     }
     return new OneTimePaymentResult(['transaction_id' => $response->getId(), 'payment_id' => $response->getPayment()->getId()]);
 }
 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());
         }
     }
 }
 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));
 }
示例#5
0
 public function transaction($payment = false, $id = false, $amount = false, $currency = 'GBP')
 {
     if (!$this->client_id) {
         throw new LaraMillException('The user has to be connected to a Paymill client to make a payment.', 401);
     }
     $transaction = new \Paymill\Models\Request\Transaction();
     $transaction->setClient($this->client_id);
     if ($id) {
         $transaction->setId($id);
     } else {
         // Get payment
         if ($payment) {
             $payment = $this->payment(false, $payment)->details();
         } else {
             $payments = $this->payment()->all();
             if (empty($payments)) {
                 throw new LaraMillException('The user has to have a payment to create a transaction.', 401);
             }
             $payment = $payments[count($payments) - 1];
         }
         $transaction->setPayment($payment->getId());
         $transaction->setAmount($amount);
         $transaction->setCurrency($currency);
     }
     $this->currentAction = 'transaction';
     return new PaymillGateway($this, $transaction);
 }
示例#6
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();
}
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));
}
示例#8
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;
 }
示例#9
0
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);
    }
}
?>
    </head>
    <body>
    <div>
        <?php