Skip to content

Commit

Permalink
1.8.0
Browse files Browse the repository at this point in the history
* Cart66: Final released
* Common: Some Error Messages were not displayed - fixed
  • Loading branch information
straightvisions-matthias-bathke committed Oct 21, 2014
1 parent 5188443 commit c1a5f77
Show file tree
Hide file tree
Showing 12 changed files with 458 additions and 279 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

Changelog
=========
1.8.0
-----
* Cart66: Final released
* Common: Some Error Messages were not displayed - fixed

1.7.2
-----
* Common: ELV/SEPA issue in checkout fixed
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ PAYMILL for WordPress
* Contributors: Matthias Reuter
* Donate link:
* Tags: paymill, creditcard, elv, payment, woocommerce, paybutton, ecommerce, debitcard, subscriptions
* Requires at least: 3.9
* Tested up to: 3.9
* Stable tag: 1.7.0
* Requires at least: 4.0
* Tested up to: 4.0
* Stable tag: 1.8.0
* License: [GPLv3 or later](http://www.gnu.org/licenses/gpl-3.0.html)

With PAYMILL you are able to provide credit card based payments for your customers.
Expand All @@ -18,16 +18,18 @@ Plugin Description

Requires:
* PHP 5.3 or higher
* WordPress 3.9.x or higher
* WordPress 4.0.x or higher
* CuRL PHP extension

Supported Shops including subscriptions support:
* WooCommerce (2.1.x) + WooCommerce Subscriptions (1.5.x)
* WooCommerce (2.2.x) + WooCommerce Subscriptions (1.5.x)
* Magic Members (1.8.x)
* Pay Button (independent, light-weight payment form)

Supported Shops without subscriptions support (yet):
* ShopPlugin (1.3.4)
* ShopPlugin (1.3.5)
* MarketPress (2.9.x)
* Cart66 Lite (1.5.1.17)


Service Description
Expand Down
5 changes: 5 additions & 0 deletions lib/css/paymill.css
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,9 @@ paymill_#form_credit, paymill_#form_elv{
}
.paymill_pay_button #payment_method_paymill{
display:none;
}

/* cart66 -_- */
#Cart66_paymill_for_wordpress_form #contactPaymentInfo li:nth-child(n+2):nth-child(-n+5){
display:none;
}
178 changes: 139 additions & 39 deletions lib/integration/cart66.inc.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
<?php

if(defined('CART66_VERSION_NUMBER')){

$GLOBALS['cart66_paymill_errors'] = array();

if(!function_exists('paymill_cart66_errorHandling')){
function paymill_cart66_errorHandling($errors){
foreach($errors as $error){
$GLOBALS['cart66_paymill_errors'][] = '<div class="paymill_error">'.$error.'</div>';
}
}
}

class paymill_Cart66ShortcodeManager extends Cart66ShortcodeManager {
public function paymill_for_wordpress_Checkout($attrs) {
if(!Cart66Session::get('Cart66Cart')->hasSubscriptionProducts()) {
Expand All @@ -27,31 +38,37 @@ protected function _buildCheckoutView($gateway) {

// use manual gateway form to gather user information
require_once(CART66_PATH . "/gateways/Cart66ManualGateway.php");
$gateway = new Cart66ManualGateway();
$gateway = new Cart66_paymill_for_wordpress();

if(!Cart66Session::get('Cart66Cart')) {
Cart66Session::set('Cart66Cart', new Cart66Cart());
}

if(!$GLOBALS['paymill_active']){
paymill_load_frontend_scripts(); // load frontend scripts

// settings
$GLOBALS['paymill_active'] = true;
$cart_total = $this->_total;
$cart_total = intval((Cart66Session::get('Cart66Cart')->getGrandTotal(false)*100));
$currency = CURRENCY_CODE;
$no_logos = false;

ob_start();

// form ids
echo '<script>
paymill_form_checkout_id = "#Cart66ManualGateway_form";
paymill_form_checkout_id = "#Cart66_paymill_for_wordpress_form";
paymill_form_checkout_submit_id = "#Cart66CheckoutButton";
paymill_shop_name = "cart66";
</script>';
</script>
';

require_once(PAYMILL_DIR.'lib/tpl/checkout_form.php');

$view .= '<h2>'.__('Payment Information','paymill').'</h2>';
$view .= ob_get_clean();
$view .= Cart66Common::getView('views/checkout.php', array('gateway' => $gateway), true, true);
$checkout = Cart66Common::getView('views/checkout.php', array('gateway' => $gateway), true, true);
$view .= str_replace(array('Cart66ManualGateway','Payment Information'),array('Cart66_paymill_for_wordpress','Contact Information'),$checkout);
}else{
$view = '<div class="paymill_notification paymill_notification_once_only"><strong>Error:</strong> Paymill can be loaded once only on the same page.</div>';
}
Expand All @@ -70,45 +87,125 @@ class Cart66_paymill_for_wordpress extends Cart66GatewayAbstract {
* The total price to charge the customer. Shipping, tax, etc. all included.
*/
protected $_total;
protected $transaction_id;

public function __construct() {

load_paymill(); // this function-call can and should be used whenever working with Paymill API
$GLOBALS['paymill_loader']->paymill_errors->setFunction('paymill_cart66_errorHandling');
$GLOBALS['paymill_source']['cart66_version'] = CART66_VERSION_NUMBER;
}

public function setPayment($p) {
$this->_payment = $p;
$skip = array('email', 'phone', 'custom-field');
$custom_payment_fields = apply_filters('cart66_after_payment_form', '');
if(is_array($custom_payment_fields)) {
foreach($custom_payment_fields as $key => $payment_field) {
if(!$payment_field['required']) {
$skip[] = $payment_field['slug'];
}
if(isset($payment_field['validator']) && $payment_field['validator'] != '') {
if(function_exists($payment_field['validator'])) {
$skip[] = $payment_field['slug'];
$data_to_validate = isset($p[$payment_field['slug']]) ? $p[$payment_field['slug']] : '';
$validated = call_user_func($payment_field['validator'], $data_to_validate);
if(!$validated['valid']) {
foreach($validated['errors'] as $key => $error) {
$this->_errors['Payment ' . $payment_field['slug'] . $key] = $error;
$this->_jqErrors[] = 'payment-' . $payment_field['slug'];
}
}
}
public function getErrors() {
if(!is_array($this->_errors)) {
$this->_errors = array();
}
return array_merge($this->_errors,$GLOBALS['cart66_paymill_errors']);
}
private function getCurrentClient(){
require_once(PAYMILL_DIR.'lib/integration/client.inc.php');
if(isset($_POST['billing_first_name']) && isset($_POST['billing_last_name'])){
$desc = $_POST['billing']['firstName'].' '.$_POST['billing']['lastName'];
}elseif(isset($_POST['billing_first_name'])){
$desc = $_POST['billing']['firstName'];
}elseif(isset($_POST['billing_last_name'])){
$desc = $_POST['billing']['lastName'];
}else{
$desc = '';
}

// create or get client
$this->clientClass = new paymill_client($_POST['payment']['email'],$desc);
return $this->clientClass->getCurrentClient();
}
private function processProducts(){
global $wpdb;
if($this->total > 0){
// make transaction
$GLOBALS['paymill_loader']->request_transaction->setAmount(round($this->total,2)); // e.g. "4200" for 42.00 EUR
$GLOBALS['paymill_loader']->request_transaction->setCurrency(CURRENCY_CODE);
if($this->paymentClass->getPreauthID() != false){
$GLOBALS['paymill_loader']->request_transaction->setPreauthorization($this->paymentClass->getPreauthID());
}else{
$GLOBALS['paymill_loader']->request_transaction->setPayment($this->paymentClass->getPaymentID());
}
$GLOBALS['paymill_loader']->request_transaction->setClient($this->client->getId());
$GLOBALS['paymill_loader']->request_transaction->setDescription($_SERVER['HTTP_HOST'].': '.$this->order_desc);
$GLOBALS['paymill_loader']->request->setSource(serialize($GLOBALS['paymill_source']));

$GLOBALS['paymill_loader']->request->create($GLOBALS['paymill_loader']->request_transaction);

$response = $GLOBALS['paymill_loader']->request->getLastResponse();

if(isset($response['body']['data']['response_code']) && $response['body']['data']['response_code'] != '20000'){
$GLOBALS['paymill_loader']->paymill_errors->setError(__($response['body']['data']['response_code'], 'paymill'));
if($GLOBALS['paymill_loader']->paymill_errors->status()){
$GLOBALS['paymill_loader']->paymill_errors->getErrors();
}
return false;
}
/*
// save data to transaction table
$wpdb->query($wpdb->prepare('
INSERT INTO '.$wpdb->prefix.'paymill_transactions (paymill_transaction_id, paymill_payment_id, paymill_client_id, cart66_order_id, paymill_transaction_time, paymill_transaction_data)
VALUES (%s,%s,%s,%d,%d,%s)',
array(
$response['body']['data']['id'],
$response['body']['data']['payment']['id'],
$response['body']['data']['client']['id'],
$this->order_id,
time(),
serialize($_POST)
)));
**/
do_action('paymill_woocommerce_products_paid', array(
'total' => $this->total,
'currency' => CURRENCY_CODE,
'client' => $response['body']['data']['client']['id']
));

$this->transaction_id = $response['body']['data']['id'];

return true;
}else{ // total is zero, so just return true

// remove preauth when not used
// @todo: Once preauths are usable for delayed payment in this plugin, we need to make a condition for this
$this->paymentClass->removePreauth();

return true;
}
foreach($p as $key => $value) {
if(!in_array($key, $skip)) {
$value = trim($value);
if($value == '') {
$keyName = ucwords(preg_replace('/([A-Z])/', " $1", $key));
$this->_errors['Payment ' . $keyName] = __('Payment ','cart66') . $keyName . __(' required','cart66');
$this->_jqErrors[] = "payment-$key";
}
private function process_payment(){
$this->client = $this->getCurrentClient();

// client retrieved, now we are ready to process the payment
if($this->client->getId() !== false && strlen($this->client->getId()) > 0){
$this->total_complete =
$this->total = (floatval($this->_total)*100);

// create payment object and preauthorization
require_once(PAYMILL_DIR.'lib/integration/payment.inc.php');
$this->paymentClass = new paymill_payment($this->client->getId(),$this->total_complete,CURRENCY_CODE); // create payment object, as it should be used for next processing instead of the token.
if($GLOBALS['paymill_loader']->paymill_errors->status()){
$GLOBALS['paymill_loader']->paymill_errors->getErrors();
return false;
}

// process subscriptions & products
if($this->processProducts()){
// success
}else{
if($GLOBALS['paymill_loader']->paymill_errors->status()){
$GLOBALS['paymill_loader']->paymill_errors->getErrors();
}
return false;
}
}else{
$GLOBALS['paymill_loader']->paymill_errors->setError(__('There was an issue with adding you as client for the payment process.', 'paymill'));
return false;
}
}

public function setPayment($p) {
if($p['email'] == '') {
$this->_errors['Email address'] = __('Email address is required','cart66');
$this->_jqErrors[] = "payment-email";
Expand All @@ -130,6 +227,9 @@ public function setPayment($p) {
$this->_jqErrors[] = 'checkout-custom-field-single';
}

$this->_payment['email'] = $p['email'];
$this->_payment['phone'] = $p['phone'];
$this->_payment['custom-field'] = $p['custom-field'];
}

public function getCreditCardTypes() {
Expand All @@ -138,16 +238,16 @@ public function getCreditCardTypes() {
}

public function initCheckout($total) {
$this->_total = $total;
$this->_total = $total;
$this->process_payment();
}

public function getTransactionResponseDescription() {
return 'Manual transaction processed: ' . $this->_total;
return array('errorcode' => '', 'errormessage' => 'No Transaction ID could be generated.');
}

public function doSale() {
$transId = 'MT-' . Cart66Common::getRandString();
return $transId;
return $this->transaction_id;
}

}
Expand Down
16 changes: 13 additions & 3 deletions lib/js/paymill.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jQuery(document).ready(function () {
jQuery(paymill_form_checkout_submit_id).show();
return false;
}

paymill.createToken({
number:jQuery('#paymill_card_number').val(),
exp_month:jQuery('#paymill_card_expiry_month').val(),
Expand All @@ -64,9 +64,15 @@ jQuery(document).ready(function () {
}, function (error, result) {
if(error){
// shows error
jQuery(".paymill_payment_errors").text(paymill_lang[error.apierror]);
if(typeof paymill_lang[error.apierror] != 'undefined'){
jQuery(".paymill_payment_errors").text(paymill_lang[error.apierror]);
}else{
jQuery(".paymill_payment_errors").text(error.apierror);
}
jQuery(paymill_form_checkout_submit_id).show();
}else{


jQuery(".paymill_payment_errors").text("");
var form = jQuery(paymill_form_checkout_id);

Expand Down Expand Up @@ -102,7 +108,11 @@ jQuery(document).ready(function () {
}, function (error, result) {
if (error) {
// shows error
jQuery(".paymill_payment_errors").text(paymill_lang[error.apierror]);
if(typeof paymill_lang[error.apierror] != 'undefined'){
jQuery(".paymill_payment_errors").text(paymill_lang[error.apierror]);
}else{
jQuery(".paymill_payment_errors").text(error.apierror);
}
jQuery(paymill_form_checkout_submit_id).show();
} else {
jQuery(".paymill_payment_errors").text("");
Expand Down
1 change: 1 addition & 0 deletions lib/scripts.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function paymill_load_frontend_scripts(){
'field_invalid_card_exp' => esc_attr__('Card is no longer valid or has expired', 'paymill'),
'field_invalid_card_cvc' => esc_attr__('Invalid checking number', 'paymill'),
'field_invalid_card_holder' => esc_attr__('Invalid cardholder', 'paymill'),
'field_invalid_amount' => esc_attr__('Invalid or missing amount', 'paymill'),
'field_invalid_amount_int' => esc_attr__('Invalid or missing amount for 3-D Secure', 'paymill'),
'field_invalid_currency' => esc_attr__('Invalid or missing currency code for 3-D Secure', 'paymill'),
'field_invalid_account_number' => esc_attr__('Missing or invalid bank account number', 'paymill'),
Expand Down
Loading

0 comments on commit c1a5f77

Please sign in to comment.