public static function getClients(array $filter = []) { $request = new \Paymill\Request(\Config::get('laramill::private')); $client = new \Paymill\Models\Request\Client(); $client->setFilter($filter); $response = $request->getAll($client); return $response; }
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)); }
<html> <head> <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());
<?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)); }
/** * 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; }
/** * Edit offer amount. * * @param int $offerId * @param EditOfferAmountRequest $request * @return */ public function editOfferAmount($offerId, EditOfferAmountRequest $request) { $response = new AjaxResponse(); $offerModel = Offer::where('id', $offerId)->first(); // Make sure offer exists if (!$offerModel) { $response->setFailMessage(trans('offers.offer_not_found')); return response($response->get(), 404)->header('Content-Type', 'application/json'); } // Create paymill request $paymillRequest = new \Paymill\Request(env('PAYMILL_API_KEY')); // Create new paymill offer object and set new amount $offer = new \Paymill\Models\Request\Offer(); $offer->setId($offerModel->paymill_offer_id)->setAmount($request->get('offer_amount')); // Save on paymill $paymillResponse = $paymillRequest->update($offer); // Update offer amount in database $offerModel->amount = $request->get('offer_amount'); $offerModel->save(); // Return json response $response->setSuccessMessage(trans('offers.offer_amount_updated')); $response->addExtraFields(['offer' => Offer::countAssociatedSubscriptions()->where('offers.id', $offerId)->first()]); return response($response->get())->header('Content-Type', 'application/json'); }
<html> <head> <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(); $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);