Plugin Directory

Changeset 1391844


Ignore:
Timestamp:
04/11/2016 08:19:00 AM (10 years ago)
Author:
maratbn
Message:

Latest updates from the 'master' branch from the official repo, which is at: https://github.com/maratbn/RainbowPayPress

Location:
rainbowpaypress/trunk
Files:
11 added
1 deleted
38 edited

Legend:

Unmodified
Added
Removed
  • rainbowpaypress/trunk/LICENSE

    r1385818 r1391844  
    44  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    55
    6   Version:        2.4.0-development_unreleased
     6  Version:        3.1.0-development_unreleased
    77
    88  Module:         rainbowpaypress/LICENSE
  • rainbowpaypress/trunk/RainbowPayPress.php

    r1385818 r1391844  
    66  Author URI: http://www.maratbn.com
    77  License: GPL3
    8   Version: 2.4.0-development_unreleased
     8  Version: 3.1.0-development_unreleased
    99  Text Domain: domain-plugin-RainbowPayPress
    1010*/
     
    1616  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    1717
    18   Version:        2.4.0-development_unreleased
     18  Version:        3.1.0-development_unreleased
    1919
    2020  Module:         rainbowpaypress/RainbowPayPress.php
     
    4242namespace plugin_RainbowPayPress;
    4343
    44 const PLUGIN_VERSION = '2.4.0-development_unreleased';
     44const PLUGIN_VERSION = '3.1.0-development_unreleased';
    4545
    4646
     
    5252const DOMAIN_PLUGIN_RAINBOW_PAY_PRESS = 'domain-plugin-RainbowPayPress';
    5353
    54 const SETTING__EMAIL_NOTIFICATIONS = 'plugin_RainbowPayPress__setting__email_notifications';
     54const SETTING__ENTITY_NAME           = 'plugin_RainbowPayPress__setting__entity_name';
     55const SETTING__EMAIL_NOTIFICATIONS   = 'plugin_RainbowPayPress__setting__email_notifications';
    5556const SETTING__FLAG_ENABLE_EMAIL_NOTIFICATIONS
    5657                            = 'plugin_RainbowPayPress__setting__flag__enable_email_notifications';
    5758const SETTING__STRIPE_LIVE_PUBLISH_KEY
    5859                                     = 'plugin_RainbowPayPress__setting__stripe_live_publish_key';
    59 const SETTING__STRIPE_LIVE_SECRET_KEY = 'plugin_RainbowPayPress__setting__stripe_live_secret_key';
     60const SETTING__STRIPE_LIVE_SECRET_KEY
     61                                     = 'plugin_RainbowPayPress__setting__stripe_live_secret_key';
    6062const SETTING__STRIPE_TEST_PUBLISH_KEY
    6163                                     = 'plugin_RainbowPayPress__setting__stripe_test_publish_key';
    62 const SETTING__STRIPE_TEST_SECRET_KEY = 'plugin_RainbowPayPress__setting__stripe_test_secret_key';
     64const SETTING__STRIPE_TEST_SECRET_KEY
     65                                     = 'plugin_RainbowPayPress__setting__stripe_test_secret_key';
    6366
    6467const SHORTCODE__RAINBOW_PAY_PRESS = 'rainbow-pay-press';
    6568
    6669const SLUG_INFO_ROOT     = 'plugin_RainbowPayPress_root';
     70const SLUG_ITEMS         = 'plugin_RainbowPayPress_items';
    6771const SLUG_SETTINGS      = 'plugin_RainbowPayPress_settings';
    6872const SLUG_TRANSACTIONS  = 'plugin_RainbowPayPress_transactions';
     
    98102        '\\plugin_RainbowPayPress\\action_admin_print_footer_scripts');
    99103    \add_action(
     104        'wp_ajax_rainbow_pay_press__admin__add_item',
     105        '\\plugin_RainbowPayPress\\action_wp_ajax_rainbow_pay_press__admin__add_item');
     106    \add_action(
    100107        'wp_ajax_rainbow_pay_press__admin__charge',
    101108        '\\plugin_RainbowPayPress\\action_wp_ajax_rainbow_pay_press__admin__charge');
    102109    \add_action(
    103         'wp_ajax_rainbow_pay_press__admin__delete',
    104         '\\plugin_RainbowPayPress\\action_wp_ajax_rainbow_pay_press__admin__delete');
     110        'wp_ajax_rainbow_pay_press__admin__delete_item',
     111        '\\plugin_RainbowPayPress\\action_wp_ajax_rainbow_pay_press__admin__delete_item');
     112    \add_action(
     113        'wp_ajax_rainbow_pay_press__admin__delete_transaction',
     114        '\\plugin_RainbowPayPress\\action_wp_ajax_rainbow_pay_press__admin__delete_transaction');
    105115    \add_action(
    106116        'wp_ajax_rainbow_pay_press__admin__get_config',
    107117        '\\plugin_RainbowPayPress\\action_wp_ajax_rainbow_pay_press__admin__get_config');
    108118    \add_action(
     119        'wp_ajax_rainbow_pay_press__admin__get_items',
     120        '\\plugin_RainbowPayPress\\action_wp_ajax_rainbow_pay_press__admin__get_items');
     121    \add_action(
    109122        'wp_ajax_rainbow_pay_press__admin__get_transactions',
    110123        '\\plugin_RainbowPayPress\\action_wp_ajax_rainbow_pay_press__admin__get_transactions');
    111124    \add_action(
     125        'wp_ajax_rainbow_pay_press__admin__modify_item',
     126        '\\plugin_RainbowPayPress\\action_wp_ajax_rainbow_pay_press__admin__modify_item');
     127    \add_action(
    112128        'wp_ajax_rainbow_pay_press__admin__send_test_email',
    113129        '\\plugin_RainbowPayPress\\action_wp_ajax_rainbow_pay_press__admin__send_test_email');
     
    126142function action_admin_enqueue_scripts($hook) {
    127143    if (($hook != 'toplevel_page_' . SLUG_INFO_ROOT) &&
     144        ($hook != 'rainbowpaypress_page_' . SLUG_ITEMS) &&
    128145        ($hook != 'rainbowpaypress_page_' . SLUG_TRANSACTIONS) &&
    129146        ($hook != 'rainbowpaypress_page_' . SLUG_SETTINGS)) return;
     
    162179    \add_submenu_page(
    163180        SLUG_INFO_ROOT,
     181        \__('RainbowPayPress Items', DOMAIN_PLUGIN_RAINBOW_PAY_PRESS),
     182        \__('Items', DOMAIN_PLUGIN_RAINBOW_PAY_PRESS),
     183        'manage_options',
     184        SLUG_ITEMS,
     185        '\\plugin_RainbowPayPress\\FragmentUtil::renderAdmin_Items');
     186
     187    \add_submenu_page(
     188        SLUG_INFO_ROOT,
    164189        \__('RainbowPayPress Transactions', DOMAIN_PLUGIN_RAINBOW_PAY_PRESS),
    165190        \__('Transactions', DOMAIN_PLUGIN_RAINBOW_PAY_PRESS),
     
    181206    if (!$wp_screen || $wp_screen->parent_base != SLUG_INFO_ROOT) return;
    182207
    183     if (Util::isCurlAvailable()) return;
    184 
    185     $strWarning = \implode([
    186             \__('RainbowPayPress warning:', DOMAIN_PLUGIN_RAINBOW_PAY_PRESS),
    187             '  ',
     208    $_renderWarning = function($strWarning) {
     209            ?><div class='notice notice-warning is-dismissible'><?php
     210              ?><p><?=\__('RainbowPayPress warning:', DOMAIN_PLUGIN_RAINBOW_PAY_PRESS)
     211                    ?>  <?=$strWarning?></p></div><?php
     212        };
     213
     214    if (!Util::isCurlAvailable()) {
     215        $_renderWarning(
    188216            \sprintf(
    189217                \__('Your PHP environment is lacking cURL support, without which it cannot communicate with the Stripe servers.  This will prevent you from charging your transactions with RainbowPayPress, for which you would need to enable PHP cURL support on your server.  If your server is running Debian or Ubuntu, this can be done by installing the package \'%s\'.',
    190218                    DOMAIN_PLUGIN_RAINBOW_PAY_PRESS),
    191                 'php5-curl')
    192         ]);
    193 
    194     ?><div class='notice notice-warning is-dismissible'><p><?=$strWarning?></p></div><?php
     219                'php5-curl'));
     220    }
     221
     222    if (Util::getOption(SETTING__ENTITY_NAME) == null) {
     223        $_renderWarning(
     224            \sprintf(
     225                \__('Your %s is not configured, and this will prevent the RainbowPayPress shortcodes from working.  You can configure it on the %s.',
     226                    DOMAIN_PLUGIN_RAINBOW_PAY_PRESS),
     227                '<b>' . \__('site / company / organization name',
     228                            DOMAIN_PLUGIN_RAINBOW_PAY_PRESS) . '</b>',
     229                '<a href=\''
     230                        . \admin_url('admin.php?page=' . SLUG_SETTINGS)
     231                    . '\'>' . \__('settings page', DOMAIN_PLUGIN_RAINBOW_PAY_PRESS) . '</a>'));
     232    }
    195233}
    196234
     
    217255</script>
    218256<?php
     257}
     258
     259function action_wp_ajax_rainbow_pay_press__admin__add_item() {
     260    /** Possible errors:
     261     *      error__insufficient_permissions
     262     *      error__duplicate_handle
     263     *      error__add_item
     264    **/
     265
     266    $arrErrors = [];
     267
     268    if (!\current_user_can('manage_options')) {
     269        \array_push($arrErrors, 'error__insufficient_permissions');
     270    }
     271
     272    $objItemAdded = null;
     273
     274    if (\count($arrErrors) == 0) {
     275        $arrDataDecoded  = \json_decode(\urldecode($_POST['data']), true);
     276
     277        $strHandle       = $arrDataDecoded['handle'];
     278        $strDescription  = $arrDataDecoded['description'];
     279        $strCost         = $arrDataDecoded['cost'];
     280
     281        if ($strHandle != null && DBUtil::tbl__items__selectSpecificForHandle($strHandle)) {
     282            \array_push($arrErrors, 'error__duplicate_handle');
     283        } else {
     284            $objItemAdded = DBUtil::tbl__items__add($strHandle,
     285                                                    $strDescription,
     286                                                    $strCost);
     287            if (!$objItemAdded) {
     288                \array_push($arrErrors, 'error__add_item');
     289            }
     290        }
     291    }
     292
     293    die(json_encode(['item'     => Util::translateItem($objItemAdded),
     294                     'success'  => (\count($arrErrors) == 0),
     295                     'errors'   => $arrErrors]));
    219296}
    220297
     
    243320    $dataTransaction = null;
    244321
    245     if (count($arrErrors) == 0) {
     322    if (\count($arrErrors) == 0) {
    246323        $id = $_POST['id'];
    247         $dataTransaction = DBUtil::selectTransaction($id);
     324        $dataTransaction = DBUtil::tbl__transactions__selectSpecific($id);
    248325        if (!$dataTransaction) {
    249326            \array_push($arrErrors, 'error__select_transaction');
     
    253330    $stripe = null;
    254331
    255     if (count($arrErrors) == 0) {
     332    if (\count($arrErrors) == 0) {
    256333
    257334        //  Based on:   https://stripe.com/docs/checkout/guides/php
     
    281358    $dataRet = [];
    282359
    283     if (count($arrErrors) == 0) {
     360    if (\count($arrErrors) == 0) {
    284361        \plugin_RainbowPayPress\Stripe\Stripe::setApiKey($stripe['secret_key']);
    285362
     
    306383                } else {
    307384                    $dataRet['stripe_charge_id'] = $charge->id;
    308                     $charged = DBUtil::updateTransactionAsCharged($id, $customer->id, $charge->id);
     385                    $charged = DBUtil::tbl__transactions__update__charged($id,
     386                                                                          $customer->id,
     387                                                                          $charge->id);
    309388                    if ($charged == null) {
    310389                        \array_push($arrErrors, 'error__update_transaction');
     
    324403    }
    325404
    326     $flagSuccess = (count($arrErrors) == 0);
     405    $flagSuccess = (\count($arrErrors) == 0);
    327406
    328407    $dataRet['success']  = $flagSuccess;
     
    332411}
    333412
    334 function action_wp_ajax_rainbow_pay_press__admin__delete() {
     413function action_wp_ajax_rainbow_pay_press__admin__delete_item() {
     414    /** Possible errors:
     415     *      error__insufficient_permissions
     416     *      error__delete_item
     417    **/
     418
     419    $arrErrors = [];
     420
     421    if (!\current_user_can('manage_options')) {
     422        \array_push($arrErrors, 'error__insufficient_permissions');
     423    }
     424
     425    if (\count($arrErrors) == 0) {
     426        $id = $_POST['id'];
     427        if (!DBUtil::tbl__items__delete($id)) {
     428            \array_push($arrErrors, 'error__delete_item');
     429        }
     430    }
     431
     432    die(json_encode(['success' => (\count($arrErrors) == 0),
     433                     'errors' => $arrErrors]));
     434}
     435
     436function action_wp_ajax_rainbow_pay_press__admin__delete_transaction() {
    335437    /** Possible errors:
    336438     *      error__insufficient_permissions
     
    344446    }
    345447
    346     if (count($arrErrors) == 0) {
     448    if (\count($arrErrors) == 0) {
    347449        $id = $_POST['id'];
    348         if (!DBUtil::deleteTransaction($id)) {
     450        if (!DBUtil::tbl__transactions__delete($id)) {
    349451            \array_push($arrErrors, 'error__delete_transaction');
    350452        }
    351453    }
    352454
    353     die(json_encode(['success' => (count($arrErrors) == 0),
     455    die(json_encode(['success' => (\count($arrErrors) == 0),
    354456                     'errors' => $arrErrors]));
    355457}
     
    374476
    375477    die(\json_encode($objRet));
     478}
     479
     480function action_wp_ajax_rainbow_pay_press__admin__get_items() {
     481    /** Possible errors:
     482     *      error__insufficient_permissions
     483     *      error__select_items
     484    **/
     485
     486    $arrErrors = [];
     487
     488    if (!\current_user_can('manage_options')) {
     489        \array_push($arrErrors, 'error__insufficient_permissions');
     490    }
     491
     492    $arrItems = null;
     493    if (\count($arrErrors) == 0) {
     494        $arrItems = DBUtil::tbl__items__selectAll();
     495        if (!$arrItems) {
     496            \array_push($arrErrors, 'error__select_items');
     497        }
     498    }
     499
     500    die(\json_encode(['success'       => (\count($arrErrors) == 0),
     501                      'errors'        => $arrErrors,
     502                      'items'         => Util::translateItems($arrItems)]));
    376503}
    377504
     
    389516
    390517    $arrTransactions = null;
    391     if (count($arrErrors) == 0) {
    392         $arrTransactions = DBUtil::selectTransactions();
     518    if (\count($arrErrors) == 0) {
     519        $arrTransactions = DBUtil::tbl__transactions__selectAll();
    393520        if (!$arrTransactions) {
    394521            \array_push($arrErrors, 'error__select_transactions');
     
    396523    }
    397524
    398     die(\json_encode(['success'       => (count($arrErrors) == 0),
     525    die(\json_encode(['success'       => (\count($arrErrors) == 0),
    399526                      'errors'        => $arrErrors,
    400527                      'transactions'  => $arrTransactions]));
     528}
     529
     530function action_wp_ajax_rainbow_pay_press__admin__modify_item() {
     531    /** Possible errors:
     532     *      error__insufficient_permissions
     533     *      error__duplicate_handle
     534     *      error__update_item
     535     **/
     536
     537    $arrErrors = [];
     538
     539    if (!\current_user_can('manage_options')) {
     540        \array_push($arrErrors, 'error__insufficient_permissions');
     541    }
     542
     543    $item = null;
     544
     545    if (\count($arrErrors) == 0) {
     546        $id              =  $_POST['id'];
     547        $arrDataDecoded  = \json_decode(\urldecode($_POST['data']), true);
     548        $handle          = getKeyValue($arrDataDecoded, 'handle');
     549
     550        if ($handle != null && DBUtil::tbl__items__selectSpecificForHandle($handle)) {
     551            \array_push($arrErrors, 'error__duplicate_handle');
     552        } else if (!DBUtil::tbl__items__update($id, $arrDataDecoded)) {
     553            \array_push($arrErrors, 'error__update_item');
     554        } else {
     555            $item = DBUtil::tbl__items__selectSpecific($id);
     556        }
     557    }
     558
     559    die(\json_encode(['success'  => (\count($arrErrors) == 0),
     560                      'errors'   => $arrErrors,
     561                      'item'     => Util::translateItem($item)]));
    401562}
    402563
     
    414575    }
    415576
    416     if (count($arrErrors) == 0) {
     577    if (\count($arrErrors) == 0) {
    417578        $strRecipient  = \get_option(SETTING__EMAIL_NOTIFICATIONS);
    418579        $strSiteURL    = \get_site_url();
     
    446607    }
    447608
    448     die(\json_encode(['success'       => (count($arrErrors) == 0),
     609    die(\json_encode(['success'       => (\count($arrErrors) == 0),
    449610                      'errors'        => $arrErrors]));
    450611}
     
    465626        $objConfig = $_POST['config'];
    466627
    467         if (array_key_exists('email_notifications', $objConfig)) {
    468             \update_option(SETTING__EMAIL_NOTIFICATIONS,
    469                            $objConfig['email_notifications']);
    470         }
    471 
    472         if (array_key_exists('flag_enable_email_notifications', $objConfig)) {
    473             \update_option(SETTING__FLAG_ENABLE_EMAIL_NOTIFICATIONS,
    474                            $objConfig['flag_enable_email_notifications']);
    475         }
    476 
    477         if (array_key_exists('stripe_key_live_secret', $objConfig)) {
    478             \update_option(SETTING__STRIPE_LIVE_SECRET_KEY, $objConfig['stripe_key_live_secret']);
    479         }
    480         if (array_key_exists('stripe_key_live_publish', $objConfig)) {
    481             \update_option(SETTING__STRIPE_LIVE_PUBLISH_KEY,
    482                            $objConfig['stripe_key_live_publish']);
    483         }
    484 
    485         if (array_key_exists('stripe_key_test_secret', $objConfig)) {
    486             \update_option(SETTING__STRIPE_TEST_SECRET_KEY, $objConfig['stripe_key_test_secret']);
    487         }
    488         if (array_key_exists('stripe_key_test_publish', $objConfig)) {
    489             \update_option(SETTING__STRIPE_TEST_PUBLISH_KEY,
    490                            $objConfig['stripe_key_test_publish']);
    491         }
     628        $_updateConfigFieldIfNecessary = function($strOption, $strField) use ($objConfig) {
     629                if (\array_key_exists($strField, $objConfig)) {
     630                    \update_option($strOption,
     631                                   $objConfig[$strField]);
     632                }
     633            };
     634
     635        $_updateConfigFieldIfNecessary(SETTING__ENTITY_NAME,
     636                                       'entity_name');
     637        $_updateConfigFieldIfNecessary(SETTING__EMAIL_NOTIFICATIONS,
     638                                       'email_notifications');
     639        $_updateConfigFieldIfNecessary(SETTING__FLAG_ENABLE_EMAIL_NOTIFICATIONS,
     640                                       'flag_enable_email_notifications');
     641        $_updateConfigFieldIfNecessary(SETTING__STRIPE_LIVE_SECRET_KEY,
     642                                       'stripe_key_live_secret');
     643        $_updateConfigFieldIfNecessary(SETTING__STRIPE_LIVE_PUBLISH_KEY,
     644                                       'stripe_key_live_publish');
     645        $_updateConfigFieldIfNecessary(SETTING__STRIPE_TEST_SECRET_KEY,
     646                                       'stripe_key_test_secret');
     647        $_updateConfigFieldIfNecessary(SETTING__STRIPE_TEST_PUBLISH_KEY,
     648                                       'stripe_key_test_publish');
    492649    }
    493650
     
    504661function action_wp_ajax_rainbow_pay_press__submit() {
    505662    /** Possible errors:
     663     *      error__item_not_found
     664     *      error__item_disallowed
    506665     *      error__insert_transaction
     666     *      error__select_transaction
    507667     **/
    508668
    509669    $arrErrors = [];
    510670
    511     $strType                = $_POST['type'];
    512     $strChargeDescription   = $_POST['charge_description'];
    513     $strProductCost         = $_POST['charge_amount'];
    514     $strStripeTokenId       = $_POST['stripe_token_id'];
    515     $strStripeEmail         = $_POST['stripe_email'];
    516     $strCustomerName        = $_POST['customer_name'];
    517     $strCustomerPhone       = $_POST['customer_phone'];
    518     $strShippingAddress     = $_POST['shipping_address'];
    519 
    520     if (!DBUtil::insertTransaction($strType,
    521                                    $strChargeDescription,
    522                                    $strProductCost,
    523                                    $strStripeTokenId,
    524                                    $strStripeEmail,
    525                                    $strCustomerName,
    526                                    $strCustomerPhone,
    527                                    $strShippingAddress)) {
    528         \array_push($arrErrors, 'error__insert_transaction');
    529     }
    530 
    531     if (count($arrErrors) == 0 && Util::getFlagEnableEmailNotifications()) {
    532         $strRecipient  = \get_option(SETTING__EMAIL_NOTIFICATIONS);
    533         $strSiteURL    = \get_site_url();
    534 
    535         if (\strlen($strRecipient) > 0) {
    536             \wp_mail(
    537                 $strRecipient,
    538                 \__('RainbowPayPress new pending transaction submitted at: ' . $strSiteURL,
    539                     DOMAIN_PLUGIN_RAINBOW_PAY_PRESS),
    540                 \implode([
    541                         \sprintf(
    542                             \__('New pending transaction has been submitted via the RainbowPayPress plugin installed onto the WordPress website at: %s',
    543                                 DOMAIN_PLUGIN_RAINBOW_PAY_PRESS),
    544                             $strSiteURL),
    545                         "\r\n\r\n",
    546                         \sprintf(
    547                             \__('Stripe transaction type: %s',
    548                                 DOMAIN_PLUGIN_RAINBOW_PAY_PRESS),
    549                             $strType),
    550                         "\r\n\r\n",
    551                         \sprintf(
    552                             \__('Charge: %s',
    553                                 DOMAIN_PLUGIN_RAINBOW_PAY_PRESS),
    554                             \implode([$strChargeDescription,
    555                                       ' -- ',
    556                                       Util::formatUSD($strProductCost)])),
    557                         "\r\n\r\n",
    558                         \sprintf(
    559                             \__('Customer: %s',
    560                                 DOMAIN_PLUGIN_RAINBOW_PAY_PRESS),
    561                             \implode([$strStripeEmail,
    562                                       ' -- ',
    563                                       $strCustomerName,
    564                                       ' -- ',
    565                                       $strCustomerPhone,
    566                                       ($strShippingAddress != "" ? (' -- ' . $strShippingAddress)
    567                                                                  : "")])),
    568                         "\r\n\r\n",
    569                         \sprintf(
    570                             \__('View / charge / delete this transaction at: %s',
    571                                 DOMAIN_PLUGIN_RAINBOW_PAY_PRESS),
    572                             \admin_url('admin.php?page=' . SLUG_TRANSACTIONS))
    573                     ]));
    574         }
    575     }
    576 
    577     die(json_encode(['success'  => (count($arrErrors) == 0),
    578                      'errors'   => $arrErrors]));
     671    $arrDataDecoded         = \json_decode(\urldecode($_POST['data']), true);
     672
     673    $strHandle              = $arrDataDecoded['handle'];
     674
     675    $objItem = DBUtil::tbl__items__selectSpecificForHandle($strHandle);
     676
     677    $strDisallowedReason = null;
     678
     679    if ($objItem) {
     680        \array_push($arrErrors, 'error__item_disallowed');
     681
     682        $strDisallowedReason = $objItem['disallowed_reason'];
     683    } else {
     684        \array_push($arrErrors, 'error__item_not_found');
     685    }
     686
     687    $objTransaction = null;
     688
     689    if (\count($arrErrors) == 0) {
     690
     691        $idTransaction = DBUtil::tbl__transactions__insert($arrDataDecoded['type'],
     692                                                           $objItem['description'],
     693                                                           $objItem['cost'],
     694                                                           $arrDataDecoded['stripe_token_id'],
     695                                                           $arrDataDecoded['stripe_email'],
     696                                                           $arrDataDecoded['customer_name'],
     697                                                           $arrDataDecoded['customer_phone'],
     698                                                           $arrDataDecoded['shipping_address']);
     699
     700        if ($idTransaction === false) {
     701            \array_push($arrErrors, 'error__insert_transaction');
     702        } else {
     703            $objTransaction = DBUtil::tbl__transactions__selectSpecific($idTransaction);
     704            if (!$objTransaction) {
     705                \array_push($arrErrors, 'error__select_transaction');
     706            } else if (Util::getFlagEnableEmailNotifications()) {
     707
     708                $strRecipient = \get_option(SETTING__EMAIL_NOTIFICATIONS);
     709
     710                if (\strlen($strRecipient) > 0) {
     711
     712                    $strSiteURL          = \get_site_url();
     713                    $strSubmissionTime   = $objTransaction['created'];
     714                    $strShippingAddress  = $objTransaction['shipping_address'];
     715
     716                    \wp_mail(
     717                        $strRecipient,
     718                        \__('RainbowPayPress new pending transaction submitted at: ' . $strSiteURL,
     719                            DOMAIN_PLUGIN_RAINBOW_PAY_PRESS),
     720                        \implode([
     721                                \sprintf(
     722                                    \__('New pending transaction has been submitted via the RainbowPayPress plugin installed onto the WordPress website at: %s',
     723                                        DOMAIN_PLUGIN_RAINBOW_PAY_PRESS),
     724                                    $strSiteURL),
     725                                "\r\n\r\n",
     726                                \sprintf(
     727                                    \__('Submission timestamp: %s',
     728                                        DOMAIN_PLUGIN_RAINBOW_PAY_PRESS),
     729                                    $strSubmissionTime ? ($strSubmissionTime .
     730                                                          ' ' .
     731                                                          \__('UTC',
     732                                                              DOMAIN_PLUGIN_RAINBOW_PAY_PRESS))
     733                                                       : 'unknown'),
     734                                "\r\n\r\n",
     735                                \sprintf(
     736                                    \__('Stripe transaction type: %s',
     737                                        DOMAIN_PLUGIN_RAINBOW_PAY_PRESS),
     738                                    $objTransaction['type']),
     739                                "\r\n\r\n",
     740                                \sprintf(
     741                                    \__('Charge: %s',
     742                                        DOMAIN_PLUGIN_RAINBOW_PAY_PRESS),
     743                                    \implode([$objTransaction['charge_description'],
     744                                              ' -- ',
     745                                              Util::formatUSD($objTransaction['charge_amount'])])),
     746                                "\r\n\r\n",
     747                                \sprintf(
     748                                    \__('Customer: %s',
     749                                        DOMAIN_PLUGIN_RAINBOW_PAY_PRESS),
     750                                    \implode([$objTransaction['stripe_email'],
     751                                              ' -- ',
     752                                              $objTransaction['customer_name'],
     753                                              ' -- ',
     754                                              $objTransaction['customer_phone'],
     755                                              ($strShippingAddress != "" ? (' -- ' .
     756                                                                            $strShippingAddress)
     757                                                                         : "")])),
     758                                "\r\n\r\n",
     759                                \sprintf(
     760                                    \__('View / charge / delete this transaction at: %s',
     761                                        DOMAIN_PLUGIN_RAINBOW_PAY_PRESS),
     762                                    \admin_url('admin.php?page=' . SLUG_TRANSACTIONS))
     763                            ]));
     764                }
     765            }
     766        }
     767    }
     768
     769    die(json_encode(['transaction'        => $objTransaction
     770                                           ? ['created' => $objTransaction['created']]
     771                                           : null,
     772                     'success'            => (\count($arrErrors) == 0),
     773                     'errors'             => $arrErrors,
     774                     'disallowed_reason'  => $strDisallowedReason]));
    579775}
    580776
    581777function action_wp_enqueue_scripts() {
     778
     779    \wp_enqueue_style('plugin__RainbowPayPress__style_css',
     780                      \plugin_dir_url(__FILE__) . '/style.css',
     781                      null,
     782                      getUVArg());
    582783
    583784    \wp_enqueue_script(
     
    642843    }
    643844
    644     DBUtil::initializeTable_Transactions();
     845    DBUtil::tbl__items__init();
     846    DBUtil::tbl__transactions__init();
    645847}
    646848
    647849function shortcode_rainbow_pay_press($atts) {
    648     if ($atts == null ||
    649         $atts['amount'] == null ||
    650         $atts['desc'] == null ||
    651         $atts['name'] == null) {
     850
     851    $strEntityName = Util::getOption(SETTING__ENTITY_NAME);
     852    if ($strEntityName == null) {
    652853        return '<b><i>' .
    653854               \sprintf(
    654                    \__('Short-code [%s] missconfigured.',
     855                   \__('Short-code [%s] cannot be fully processed because entity name not configured.',
    655856                       DOMAIN_PLUGIN_RAINBOW_PAY_PRESS),
    656857                   SHORTCODE__RAINBOW_PAY_PRESS) .
     858               '</i></b>';
     859    }
     860
     861    $strItemHandle = $atts ? $atts['item'] : null;
     862    if ($strItemHandle == null) {
     863        return '<b><i>' .
     864               \sprintf(
     865                   \__('Short-code [%s] cannot be fully processed because required parameter "%s" is not included.',
     866                       DOMAIN_PLUGIN_RAINBOW_PAY_PRESS),
     867                   SHORTCODE__RAINBOW_PAY_PRESS,
     868                   'item') .
     869               '</i></b>';
     870    }
     871
     872    $objItem = DBUtil::tbl__items__selectSpecificForHandle($strItemHandle);
     873    if (!$objItem) {
     874        return '<b><i>' .
     875               \sprintf(
     876                   \__('Short-code [%s] cannot be fully processed because no item with the specified handle "%s" was found.',
     877                       DOMAIN_PLUGIN_RAINBOW_PAY_PRESS),
     878                   SHORTCODE__RAINBOW_PAY_PRESS,
     879                   $strItemHandle) .
    657880               '</i></b>';
    658881    }
     
    662885                ' data-plugin-rainbow-pay-press-type="' . \esc_attr($atts['type']) .
    663886                                                    '"') .
    664                 ' data-plugin-rainbow-pay-press-amount="' . \esc_attr($atts['amount']) .
     887                ' data-plugin-rainbow-pay-press-amount="' . \esc_attr($objItem['cost']) .
    665888                                                      '"' .
    666                 ' data-plugin-rainbow-pay-press-name="' . \esc_attr($atts['name']) .
     889                ' data-plugin-rainbow-pay-press-name="' . \esc_attr($strEntityName) .
    667890                                                    '"' .
    668                 ' data-plugin-rainbow-pay-press-desc="' . \esc_attr($atts['desc']) .
     891                ' data-plugin-rainbow-pay-press-desc="' . \esc_attr($objItem['description']) .
    669892                                                    '"' .
    670 
    671                 ($atts['fields'] == null ? "" :
    672                 ' data-plugin-rainbow-pay-press-fields="' . \esc_attr($atts['fields']) .
     893                ' data-plugin-rainbow-pay-press-handle="' . \esc_attr($strItemHandle) .
     894                                                      '"' .
     895
     896                ($atts['override_fields'] == null ? "" :
     897                ' data-plugin-rainbow-pay-press-fields="' . \esc_attr($atts['override_fields']) .
    673898                                                     '"') .
    674899
  • rainbowpaypress/trunk/RainbowPayPress_util.php

    r1385818 r1391844  
    66  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    77
    8   Version:        2.4.0-development_unreleased
     8  Version:        3.1.0-development_unreleased
    99
    1010  Module:         rainbowpaypress/RainbowPayPress_util.php
     
    3434
    3535
     36function getKeyValue($arr, $key, $default = null) {
     37    if (!$arr) return $default;
     38
     39    if (\array_key_exists($key, $arr)) {
     40        return $arr[$key];
     41    }
     42
     43    return $default;
     44}
     45
    3646function getDateTimeNow() {
    3747    $ms = \time() * 1000 + \substr(\microtime(), 2, 3);
    38     return \gmdate('Y-m-d  H:i:s', $ms / 1000);
     48    return \gmdate('Y-m-d H:i:s', $ms / 1000);
    3949}
    4050
     
    4858
    4959class DBUtil {
    50     static function deleteTransaction($id) {
    51         global $wpdb;
    52         return $wpdb->delete(DBUtil::getTableName_Transactions(), ['id' => $id]);
    53     }
    54 
    55     static function getTableName_Transactions() {
     60    static function tbl__items__add($strHandle, $strDescription, $strCost) {
     61        global $wpdb;
     62        if (!$wpdb->insert(
     63                        DBUtil::tbl__items__getName(), [
     64                            'handle'                => $strHandle,
     65                            'description'           => $strDescription,
     66                            'cost'                  => $strCost,
     67                            'currency'              => 'usd_x_100'
     68                        ])) return false;
     69
     70        return DBUtil::tbl__items__selectSpecific($wpdb->insert_id);
     71    }
     72
     73    static function tbl__items__delete($id) {
     74        global $wpdb;
     75        return $wpdb->delete(DBUtil::tbl__items__getName(), ['id' => $id]);
     76    }
     77
     78    static function tbl__items__getName() {
     79        global $wpdb;
     80        return $wpdb->prefix . 'plugin_rainbow_pay_press_items';
     81    }
     82
     83    static function tbl__items__init() {
     84        $strTableName = DBUtil::tbl__items__getName();
     85        global $wpdb;
     86        $sql = "CREATE TABLE $strTableName (
     87                id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
     88                handle varchar(20) NOT NULL UNIQUE,
     89                cost int NOT NULL,
     90                currency varchar(20) NOT NULL,
     91                description varchar(1000) NOT NULL,
     92                is_disallowed boolean,
     93                disallowed_reason varchar(1000)
     94            );";
     95        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
     96        dbDelta($sql);
     97    }
     98
     99    static function tbl__items__selectAll() {
     100        $strTableName = DBUtil::tbl__items__getName();
     101
     102        global $wpdb;
     103        return $wpdb->get_results("SELECT id,
     104                                          handle,
     105                                          cost,
     106                                          description,
     107                                          is_disallowed,
     108                                          disallowed_reason
     109                                     FROM $strTableName", ARRAY_A);
     110    }
     111
     112    static function tbl__items__selectSpecific($id) {
     113        $strTableName = DBUtil::tbl__items__getName();
     114
     115        global $wpdb;
     116        $arrItem = $wpdb->get_results($wpdb->prepare("SELECT id,
     117                                                             handle,
     118                                                             cost,
     119                                                             description,
     120                                                             is_disallowed,
     121                                                             disallowed_reason
     122                                                        FROM $strTableName
     123                                                       WHERE id=%d",
     124                                                     $id),
     125                                      ARRAY_A);
     126        if (!$arrItem || count($arrItem) == 0) return false;
     127
     128        return $arrItem[0];
     129    }
     130
     131    static function tbl__items__selectSpecificForHandle($handle) {
     132        $strTableName = DBUtil::tbl__items__getName();
     133
     134        global $wpdb;
     135        $arrItem = $wpdb->get_results($wpdb->prepare("SELECT id,
     136                                                             handle,
     137                                                             cost,
     138                                                             description,
     139                                                             is_disallowed,
     140                                                             disallowed_reason
     141                                                        FROM $strTableName
     142                                                       WHERE handle=%s",
     143                                                     $handle),
     144                                      ARRAY_A);
     145        if (!$arrItem || count($arrItem) == 0) return false;
     146
     147        return $arrItem[0];
     148    }
     149
     150    static function tbl__items__update($id, $objData) {
     151        global $wpdb;
     152        if(!$wpdb->update(DBUtil::tbl__items__getName(),
     153                          $objData,
     154                          ['id' => $id])) return false;
     155        return true;
     156    }
     157
     158
     159    static function tbl__transactions__delete($id) {
     160        global $wpdb;
     161        return $wpdb->delete(DBUtil::tbl__transactions__getName(), ['id' => $id]);
     162    }
     163
     164    static function tbl__transactions__getName() {
    56165        global $wpdb;
    57166        return $wpdb->prefix . 'plugin_rainbow_pay_press_transactions';
    58167    }
    59168
    60     static function initializeTable_Transactions() {
    61         $strTableName = DBUtil::getTableName_Transactions();
     169    static function tbl__transactions__init() {
     170        $strTableName = DBUtil::tbl__transactions__getName();
    62171        global $wpdb;
    63172        $sql = "CREATE TABLE $strTableName (
     
    71180                stripe_token_id varchar(100) NOT NULL,
    72181                stripe_email varchar(200) NOT NULL,
    73                 customer_name varchar(200) NOT NULL,
    74                 customer_phone varchar(100) NOT NULL,
     182                customer_name varchar(200),
     183                customer_phone varchar(100),
    75184                shipping_address varchar(300),
    76185                stripe_customer_id varchar(100),
     
    81190    }
    82191
    83     static function insertTransaction($strType,
    84                                       $strChargeDescription,
    85                                       $strProductCost,
    86                                       $strStripeTokenId,
    87                                       $strStripeEmail,
    88                                       $strCustomerName,
    89                                       $strCustomerPhone,
    90                                       $strShippingAddress) {
    91 
    92         global $wpdb;
    93         if (!$wpdb->insert(DBUtil::getTableName_Transactions(), [
     192    static function tbl__transactions__insert($strType,
     193                                              $strChargeDescription,
     194                                              $strProductCost,
     195                                              $strStripeTokenId,
     196                                              $strStripeEmail,
     197                                              $strCustomerName,
     198                                              $strCustomerPhone,
     199                                              $strShippingAddress) {
     200
     201        global $wpdb;
     202        if (!$wpdb->insert(DBUtil::tbl__transactions__getName(), [
    94203                            'type'                 => $strType,
    95204                            'created'              => getDateTimeNow(),
     
    103212                            'shipping_address'     => $strShippingAddress])) return false;
    104213
    105         return true;
    106     }
    107 
    108     static function selectTransaction($id) {
    109         $strTableName = DBUtil::getTableName_Transactions();
     214        return $wpdb->insert_id;
     215    }
     216
     217    static function tbl__transactions__selectAll() {
     218        $strTableName = DBUtil::tbl__transactions__getName();
     219
     220        global $wpdb;
     221        return $wpdb->get_results("SELECT id,
     222                                          type,
     223                                          created,
     224                                          charged,
     225                                          charge_description,
     226                                          charge_amount,
     227                                          stripe_token_id,
     228                                          stripe_email,
     229                                          customer_name,
     230                                          customer_phone,
     231                                          shipping_address,
     232                                          stripe_customer_id,
     233                                          stripe_charge_id
     234                                     FROM $strTableName ORDER BY charged, created", ARRAY_A);
     235    }
     236
     237    static function tbl__transactions__selectSpecific($id) {
     238        $strTableName = DBUtil::tbl__transactions__getName();
    110239
    111240        global $wpdb;
     
    130259    }
    131260
    132     static function selectTransactions() {
    133         $strTableName = DBUtil::getTableName_Transactions();
    134 
    135         global $wpdb;
    136         return $wpdb->get_results("SELECT id,
    137                                           type,
    138                                           created,
    139                                           charged,
    140                                           charge_description,
    141                                           charge_amount,
    142                                           stripe_token_id,
    143                                           stripe_email,
    144                                           customer_name,
    145                                           customer_phone,
    146                                           shipping_address,
    147                                           stripe_customer_id,
    148                                           stripe_charge_id
    149                                      FROM $strTableName ORDER BY charged, created", ARRAY_A);
    150     }
    151 
    152     static function updateTransactionAsCharged($id, $stripe_customer_id, $stripe_charge_id) {
     261    static function tbl__transactions__update__charged($id,
     262                                                       $stripe_customer_id,
     263                                                       $stripe_charge_id) {
    153264
    154265        $date_time = getDateTimeNow();
    155266
    156267        global $wpdb;
    157         if(!$wpdb->update(DBUtil::getTableName_Transactions(),
     268        if(!$wpdb->update(DBUtil::tbl__transactions__getName(),
    158269                          ['charged'             => $date_time,
    159270                           'stripe_customer_id'  => $stripe_customer_id,
     
    190301      <h2><?=\__('Usage Info:', DOMAIN_PLUGIN_RAINBOW_PAY_PRESS)?></h2>
    191302      <p>Use the shortcode
    192          <code>[<?=SHORTCODE__RAINBOW_PAY_PRESS?> type='<span style='color:red'>live</span>' amount=1234 name="My entity" desc="Buy this" label="Click to buy" fields='!phone shipping']</code>
     303         <code>[<?=SHORTCODE__RAINBOW_PAY_PRESS?> type='<span style='color:red'>live</span>' item="handle" label="Click to buy" override_fields='!phone shipping']</code>
    193304         to embed a Stripe payment widget on
    194305         any page or post.
     
    203314        <ul class='rpp_subitems'>
    204315          <li>
    205             <code>amount</code>
    206             <p>The amount to charge in US cents.</p>
    207           </li>
    208           <li>
    209             <code>name</code>
    210             <p>Your site / company / organization name.</p>
    211           </li>
    212           <li>
    213             <code>desc</code>
    214             <p>Description of the product / service / fee you're charging for.</p>
     316            <code>item</code>
     317            <p>The handle of the item to sell.  Items and their handles can be specified
     318              <a href='<?=\admin_url('admin.php?page=' . SLUG_ITEMS)?>'>here</a>.</p>
    215319          </li>
    216320        </ul>
     
    238342          </li>
    239343          <li>
    240             <code>fields</code>
     344            <code>override_fields</code>
    241345            <p>
    242               Specifies which fields to include or exclude on the buyer entry form.
     346              Overrides default settings for which fields to include or exclude on the buyer entry form.
    243347              Available fields:
    244348              <ul class='rpp_subitems'>
     
    260364    }
    261365
     366    static function renderAdmin_Items() {
     367        //  Based on http://codex.wordpress.org/Administration_Menus
     368        if (!\current_user_can('manage_options' ))  {
     369            \wp_die(\__('You do not have sufficient permissions to access this page.',
     370                        DOMAIN_PLUGIN_RAINBOW_PAY_PRESS));
     371        }
     372    ?>
     373    <div class='wrap'>
     374      <h3><?=\__('Items to be included in transactions:', DOMAIN_PLUGIN_RAINBOW_PAY_PRESS)?></h3>
     375      <p>
     376        <span data-plugin-rainbow-pay-press-role='add-new-item'></span>
     377      </p>
     378      <p>
     379        <span data-plugin-rainbow-pay-press-role='items'></span>
     380      </p>
     381    </div>
     382    <?php
     383    }
     384
    262385    static function renderAdmin_Transactions() {
    263386        //  Based on http://codex.wordpress.org/Administration_Menus
     
    267390        }
    268391    ?>
    269     <style>
    270         .transaction--even {
    271             background-color: #eee;
    272         }
    273         .transaction--odd {
    274             background-color: #ddd;
    275         }
    276     </style>
    277392    <div class='wrap'>
    278393      <h3><?=\__('Pending Transactions:', DOMAIN_PLUGIN_RAINBOW_PAY_PRESS)?></h3>
     
    333448
    334449    static function getConfig() {
    335         return ['email_notifications'     => Util::getOption(SETTING__EMAIL_NOTIFICATIONS),
     450        return ['entity_name'             => Util::getOption(SETTING__ENTITY_NAME),
     451                'email_notifications'     => Util::getOption(SETTING__EMAIL_NOTIFICATIONS),
    336452                'flag_enable_email_notifications'
    337453                                          => Util::getFlagEnableEmailNotifications(),
     
    355471        return \function_exists('\\curl_init');
    356472    }
     473
     474    static function translateItem($objItemDB) {
     475        if (!$objItemDB) return null;
     476
     477        return ['id'                 => $objItemDB['id'],
     478                'handle'             => $objItemDB['handle'],
     479                'description'        => $objItemDB['description'],
     480                'cost'               => \intval($objItemDB['cost']),
     481                'is_disallowed'      => $objItemDB['is_disallowed'] ? true : false,
     482                'disallowed_reason'  => $objItemDB['disallowed_reason']];
     483    }
     484
     485    static function translateItems($arrItems) {
     486        if (!$arrItems) return null;
     487
     488        $arrItemsTranslated = [];
     489
     490        foreach ($arrItems as $objItem) {
     491            \array_push($arrItemsTranslated, Util::translateItem($objItem));
     492        }
     493
     494        return $arrItemsTranslated;
     495    }
    357496}
    358497?>
  • rainbowpaypress/trunk/js/le_requirejs/admin/collection_orig__transaction.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/admin/collection_orig__transaction.js
     
    3636define(['backbone',
    3737        'jquery',
     38        'util',
    3839        'model_orig__app_common',
    3940        'admin/model_orig__transaction'
    40     ], function (backbone, $, model_orig__app_common, ModelOrig_Transaction) {
     41    ], function (backbone, $, util, model_orig__app_common, ModelOrig_Transaction) {
    4142
    4243        return new (backbone.Collection.extend({
     
    9394
    9495                                model_orig__transaction.set({
    95                                         'charged':             objData['charged'] == null
    96                                                                 ? null
    97                                                                 : new window
    98                                                                        .Date(objData['charged']
    99                                                                                         + ' GMT'),
     96                                        'charged':             util.parseDate(objData['charged']),
    10097                                        'stripe_customer_id':  objData['stripe_customer_id'],
    10198                                        'stripe_charge_id':    objData['stripe_charge_id']
     
    109106                        var $xhr = $.ajax(model_orig__app_common.get('ajax_url'), {
    110107                                              data: {
    111                                                       'action':  'rainbow_pay_press__admin__delete',
     108                                                      'action':  'rainbow_pay_press__admin__delete_transaction',
    112109                                                      'id':      model_orig__transaction.get('id')
    113110                                                  },
  • rainbowpaypress/trunk/js/le_requirejs/admin/main_admin.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/admin/main_admin.js
     
    3636define(['jquery',
    3737        'model_orig__app_common',
     38        'admin/collection_orig__item',
    3839        'admin/collection_orig__transaction',
    3940        'admin/model_orig__config',
     41        'admin/view_agg__button__add_new_item',
    4042        'admin/view_agg__table__config',
     43        'admin/view_agg__table__items',
    4144        'admin/view_agg__table__transactions'
    4245    ], function($,
    4346                model_orig__app_common,
    44                 collection_orig_transaction,
     47                collection_orig__item,
     48                collection_orig__transaction,
    4549                model_orig__config,
     50                ViewAgg_Button_AddNewItem,
    4651                ViewAgg_Table_Config,
     52                ViewAgg_Table_Items,
    4753                ViewAgg_Table_Transactions) {
    4854
    4955        function _processSpansWithRoles(params) {
    5056
    51             (new ViewAgg_Table_Config())
    52                         .$el
    53                         .appendTo($("span[data-plugin-rainbow-pay-press-role=app-config]"));
     57            var $snapAppConfig = $("span[data-plugin-rainbow-pay-press-role=app-config]");
     58            if ($snapAppConfig) {
     59                (new ViewAgg_Table_Config()).$el.appendTo($snapAppConfig);
     60            }
    5461
    5562
    56             collection_orig_transaction.fetch();
     63            var $snapAddNewItem = $("span[data-plugin-rainbow-pay-press-role=add-new-item]");
     64            if ($snapAddNewItem) {
     65                (new ViewAgg_Button_AddNewItem()).$el.appendTo($snapAddNewItem);
     66            }
    5767
    58             function _processSpans($elSpans, params) {
     68
     69            var $snapItems = $("span[data-plugin-rainbow-pay-press-role=items]");
     70            if ($snapItems) {
     71                collection_orig__item.fetch();
     72                (new ViewAgg_Table_Items()).$el.appendTo($snapItems);
     73            }
     74
     75
     76            function _processTransactionSpans($elSpans, params) {
     77                if ($elSpans.length == 0) return;
     78
     79                collection_orig__transaction.fetch();
     80
    5981                for (var i = 0; i < $elSpans.length; i++) {
    6082                    var $elSpan = $($elSpans[i]);
     83                    if (!$elSpan) continue;
    6184
    6285                    (new ViewAgg_Table_Transactions(params)).$el.appendTo($elSpan);
     
    6487            }
    6588
    66             _processSpans($("span[data-plugin-rainbow-pay-press-role=transactions]"));
    67             _processSpans($("span[data-plugin-rainbow-pay-press-role=transactions-charged]"),
     89            _processTransactionSpans(
     90                          $("span[data-plugin-rainbow-pay-press-role=transactions-charged]"),
    6891                          {flag_exclude_uncharged: true});
    69             _processSpans($("span[data-plugin-rainbow-pay-press-role=transactions-pending]"),
     92            _processTransactionSpans(
     93                          $("span[data-plugin-rainbow-pay-press-role=transactions-pending]"),
    7094                          {flag_exclude_charged: true});
    7195        }
     
    83107
    84108                model_orig__config.set({
     109                        'entity_name':              params['entity_name'],
    85110                        'email_notifications':      params['email_notifications'],
    86111                        'flag_enable_email_notifications':
  • rainbowpaypress/trunk/js/le_requirejs/admin/model_orig__config.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/admin/model_orig__config.js
     
    4444
    4545                defaults: {
     46                        'entity_name':                      null,
    4647                        'email_notifications':              null,
    4748                        'flag_enable_email_notifications':  false,
  • rainbowpaypress/trunk/js/le_requirejs/admin/model_orig__transaction.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/admin/model_orig__transaction.js
     
    3434
    3535
    36 define(['backbone'], function (backbone) {
    37 
    38         //  This will parse a date string in the format "2016-04-03 05:10:41" that is assumed to
    39         //  be in UTC time.
    40         function _parseDate(strDate) {
    41             if (!strDate) return null;
    42 
    43             var arrParts = strDate.split(' ');
    44             return new Date(arrParts[0] + 'T' + arrParts[1] + 'Z');
    45         }
     36define(['backbone', 'util'], function (backbone, util) {
    4637
    4738        return backbone.Model.extend({
     
    6960                                'id':                   data['id'],
    7061                                'type':                 data['type'],
    71                                 'created':              _parseDate(data['created']),
    72                                 'charged':              _parseDate(data['charged']),
     62                                'created':              util.parseDate(data['created']),
     63                                'charged':              util.parseDate(data['charged']),
    7364                                'charge_description':   data['charge_description'],
    7465                                'charge_amount':        data['charge_amount'],
  • rainbowpaypress/trunk/js/le_requirejs/admin/view_agg__button.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/admin/view_agg__button.js
  • rainbowpaypress/trunk/js/le_requirejs/admin/view_agg__button__send_test_email.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/admin/view_agg__button__send_test_email.js
  • rainbowpaypress/trunk/js/le_requirejs/admin/view_agg__span__date.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/admin/view_agg__span__date.js
     
    3333
    3434
    35 define(['backbone', 'jquery'], function(backbone, $) {
    36 
    37 
    38         function _getDigits(num, len) {
    39             var str = "" + num;
    40             while (str.length < len) {
    41                 str = '0' + str;
    42             }
    43             return str;
    44         }
    45 
    46         function _getDateComponents(date) {
    47             if (!date) return null;
    48 
    49             return {
    50                     year:   date.getFullYear(),
    51                     month:  _getDigits(date.getMonth() + 1, 2),
    52                     day:    _getDigits(date.getDate(), 2),
    53                     hour:   _getDigits(date.getHours(), 2),
    54                     min:    _getDigits(date.getMinutes(), 2),
    55                     sec:    _getDigits(date.getSeconds(), 2),
    56                     msec:   _getDigits(date.getMilliseconds(), 3)
    57                 };
    58         }
    59 
    60         function _getDateReprTZName(date) {
    61             var arrMatchTZ = date && date.toString().match(/\([^)]+\)/g);
    62             return arrMatchTZ && arrMatchTZ.length == 1 && arrMatchTZ[0] || "";
    63         }
    64 
    65         function _getDateStrings(date) {
    66 
    67             var date_components = _getDateComponents(date);
    68             if (!date_components) return null;
    69 
    70             function _getWeekday() {
    71                 return (['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'])[date.getDay()];
    72             }
    73 
    74             return {
    75                     'weekday':  _getWeekday(),
    76                     'date':     date_components.year + '-' + date_components.month
    77                                                      + '-' + date_components.day,
    78                     'time':     date_components.hour + ':' + date_components.min
    79                                                      + ':' + date_components.sec,
    80                     'tz':       _getDateReprTZName(date)
    81                 };
    82         }
    83 
    84         function _getDateRepr(date) {
    85 
    86             var date_strings = _getDateStrings(date);
    87             if (!date_strings) return null;
    88 
    89             return date_strings.weekday + ' ' + date_strings.date
    90                                        + '  ' + date_strings.time
    91                                        + '  ' + date_strings.tz;
    92         }
    93 
     35define(['backbone', 'jquery', 'util'], function(backbone, $, util) {
    9436
    9537        return backbone.View.extend({
     
    10951                                                       .appendTo(this.$el);
    11052
    111                         var date_strings = _getDateStrings(date);
     53                        var date_strings = util.getDateStrings(date);
    11254                        if (!date_strings) {
    11355                            $spanWeekday.text("");
  • rainbowpaypress/trunk/js/le_requirejs/admin/view_agg__table__config.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/admin/view_agg__table__config.js
     
    8686                        this.$el.append($("<tr>").append($("<th>").append($buttonRefresh)));
    8787
     88                        (new ViewAgg_Tr_Config_Option_String({
     89                                                field:   'entity_name',
     90                                                label:   "Your site / company / organization name:",
     91                                                prompt:  "Enter your site / company / organization name:"
     92                                            })).$el
     93                                               .appendTo(this.$el);
     94
    8895                        (new ViewAgg_Tr_Config_Option_Boolean({
    8996                                                field:   'flag_enable_email_notifications',
  • rainbowpaypress/trunk/js/le_requirejs/admin/view_agg__table__transactions.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/admin/view_agg__table__transactions.js
  • rainbowpaypress/trunk/js/le_requirejs/admin/view_agg__tr__config__notes.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/admin/view_agg__tr__config__notes.js
  • rainbowpaypress/trunk/js/le_requirejs/admin/view_agg__tr__config__option.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/admin/view_agg__tr__config__option.js
  • rainbowpaypress/trunk/js/le_requirejs/admin/view_agg__tr__config__option__boolean.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/admin/view_agg__tr__config__option__string.js
  • rainbowpaypress/trunk/js/le_requirejs/admin/view_agg__tr__config__option__string.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/admin/view_agg__tr__config__option__string.js
     
    7272                                                                                .get(params.field)
    7373                                                                      || "");
    74                                         if (!strValNew) return;
     74                                        if (strValNew == null) return;
    7575
    7676                                        var objConfig = {};
  • rainbowpaypress/trunk/js/le_requirejs/admin/view_agg__tr__config__option__string__email_notifications.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/admin/view_agg__tr__config__option__string__email_notifications.js
  • rainbowpaypress/trunk/js/le_requirejs/admin/view_agg__tr__transaction.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/admin/view_agg__tr__transaction.js
     
    4545                ViewAgg_Span_Date,
    4646                ViewAgg_Tr_WHeader) {
    47 
    48         function _flipToSingleCol() {
    49             var totalCols = this.$el.children().length;
    50 
    51             this.$el.empty();
    52 
    53             return _td().attr({'colspan':  totalCols,
    54                                'style':    'text-align:center'})
    55                         .appendTo(this.$el);
    56         }
    5747
    5848        function _getStripeUrlForCharge(type, stripe_charge_id) {
     
    190180
    191181                markAsCharged: function() {
    192                         _flipToSingleCol.call(this).text("--- Charged ---");
     182                        this.markAs("--- Charged ---");
    193183                    },
    194184
    195185                markAsDeleted: function() {
    196                         _flipToSingleCol.call(this).text("--- Deleted ---");
     186                        this.markAs("--- Deleted ---");
    197187                    }
    198188            });
  • rainbowpaypress/trunk/js/le_requirejs/admin/view_agg__tr__w_header.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/admin/view_agg__tr__w_header.js
     
    5151                        var $thHeader = $('<th>');
    5252
    53                         this.$el.append($thHeader);
     53                        this.$el.attr('valign', 'top')
     54                                .append($thHeader);
    5455
    5556                        this.get_$thHeader = function() {
    5657                                return $thHeader;
    5758                            };
     59                    },
     60
     61                _flipToSingleCol: function() {
     62                        var totalCols = this.$el.children().length;
     63
     64                        this.$el.empty();
     65
     66                        return $('<td>').attr({'colspan':  totalCols,
     67                                               'style':    'text-align:center'})
     68                                        .appendTo(this.$el);
     69                    },
     70
     71                markAs: function(strText) {
     72                        this._flipToSingleCol().text(strText);
    5873                    }
    5974            });
  • rainbowpaypress/trunk/js/le_requirejs/backbone-private.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/backbone-private.js
  • rainbowpaypress/trunk/js/le_requirejs/common.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/common.js
  • rainbowpaypress/trunk/js/le_requirejs/jquery-private.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/jquery-private.js
  • rainbowpaypress/trunk/js/le_requirejs/main.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/main.js
  • rainbowpaypress/trunk/js/le_requirejs/model_orig__app_common.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/model_orig__app_common.js
  • rainbowpaypress/trunk/js/le_requirejs/public/main_public.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/public/main_public.js
     
    4545        function _processShortcodes() {
    4646            function _processSpan($elSpan) {
    47                 var type    = $elSpan.attr('data-plugin-rainbow-pay-press-type') || 'test',
    48                     amount  = $elSpan.attr('data-plugin-rainbow-pay-press-amount'),
    49                     fields  = $elSpan.attr('data-plugin-rainbow-pay-press-fields'),
    50                     name    = $elSpan.attr('data-plugin-rainbow-pay-press-name'),
    51                     desc    = $elSpan.attr('data-plugin-rainbow-pay-press-desc'),
    52                     info    = $elSpan.attr('data-plugin-rainbow-pay-press-info'),
    53                     label   = $elSpan.attr('data-plugin-rainbow-pay-press-label');
     47                var label   = $elSpan.attr('data-plugin-rainbow-pay-press-label');
    5448
    5549                var $buttonMakePayment = $('<button>').text(label || "Pay with Stripe")
     
    6862                        } else {
    6963                            (view_agg__div__transactionCached =
    70                                                     new ViewAgg_Div_Transaction({
    71                                                                 type:          type,
    72                                                                 amount:        amount,
    73                                                                 name:          name,
    74                                                                 desc:          desc,
    75                                                                 info:          info,
    76                                                                 fields:        fields
    77                                                             })).$el.appendTo($elSpan);
     64                                new ViewAgg_Div_Transaction({
     65                                            type:    $elSpan
     66                                                        .attr(
     67                                                          'data-plugin-rainbow-pay-press-type')
     68                                                      || 'test',
     69                                            amount:  $elSpan
     70                                                        .attr(
     71                                                          'data-plugin-rainbow-pay-press-amount'),
     72                                            name:    $elSpan
     73                                                        .attr(
     74                                                          'data-plugin-rainbow-pay-press-name'),
     75                                            desc:    $elSpan
     76                                                        .attr(
     77                                                          'data-plugin-rainbow-pay-press-desc'),
     78                                            info:    $elSpan
     79                                                        .attr(
     80                                                          'data-plugin-rainbow-pay-press-info'),
     81                                            fields:  $elSpan
     82                                                        .attr(
     83                                                          'data-plugin-rainbow-pay-press-fields'),
     84                                            handle:  $elSpan
     85                                                        .attr(
     86                                                          'data-plugin-rainbow-pay-press-handle')
     87                                        })).$el.appendTo($elSpan);
    7888                        }
    7989                    });
  • rainbowpaypress/trunk/js/le_requirejs/public/model_info__stripe_checkout.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/public/model_info__stripe_checkout.js
  • rainbowpaypress/trunk/js/le_requirejs/public/model_info__transaction_details.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/public/model_info__transaction_details.js
     
    3333
    3434
    35 define(['backbone',
    36         'jquery',
     35define(['jquery',
     36        'model_info__details_base',
    3737        'model_orig__app_common',
    3838        'public/model_orig__app_public',
    39     ], function(backbone, $, model_orig__app_common, model_orig__app_public) {
     39    ], function($,
     40                ModelInfo_DetailsBase,
     41                model_orig__app_common,
     42                model_orig__app_public) {
    4043
    41         return backbone.Model.extend({
     44        return ModelInfo_DetailsBase.extend({
    4245
    4346                defaults: {
     
    4952                        'customer_name':        null,
    5053                        'customer_phone':       null,
     54                        'handle':               null,
    5155                        'shipping_address':     null
    52                     },
    53 
    54                 doCheckForFieldsWithMissingValues: function(model_orig__fields) {
    55                         var arrFieldsRequired = model_orig__fields.getFieldsRequired();
    56                             arrFieldsWithMissingValues = [];
    57 
    58                         for (var i = 0; i < arrFieldsRequired.length; i++) {
    59                             var field = arrFieldsRequired[i];
    60                             var value = this.attributes[field];
    61                             if (!value) {
    62                                 arrFieldsWithMissingValues.push(field);
    63                             }
    64                         }
    65 
    66                         this.trigger('fields_with_missing_values', {
    67                                         fields: arrFieldsWithMissingValues
    68                                      });
    69 
    70                         return arrFieldsWithMissingValues.length > 0 && true;
    7156                    },
    7257
     
    7459                        var $xhr = $.post
    7560                                      (model_orig__app_common.get('ajax_url'), {
    76                                           action:              'rainbow_pay_press__submit',
    77                                           type:                this.attributes['type'],
    78                                           charge_description:  this.attributes
    79                                                                            ['charge_description'],
    80                                           charge_amount:       this.attributes['charge_amount'],
    81                                           stripe_token_id:     this.attributes['stripe_token_id'],
    82                                           stripe_email:        this.attributes['stripe_email'],
    83                                           customer_name:       this.attributes['customer_name'],
    84                                           customer_phone:      this.attributes['customer_phone'],
    85                                           shipping_address:    this.attributes['shipping_address']
     61                                          'action':  'rainbow_pay_press__submit',
     62                                          'data':    window.encodeURIComponent(
     63                                                       window.JSON.stringify({
     64                                                         'type':                this.attributes
     65                                                                                        ['type'],
     66                                                         'handle':              this.attributes
     67                                                                                        ['handle'],
     68                                                         'stripe_token_id':     this.attributes
     69                                                                                        ['stripe_token_id'],
     70                                                         'stripe_email':        this.attributes
     71                                                                                        ['stripe_email'],
     72                                                         'customer_name':       this.attributes
     73                                                                                        ['customer_name'],
     74                                                         'customer_phone':      this.attributes
     75                                                                                        ['customer_phone'],
     76                                                         'shipping_address':    this.attributes
     77                                                                                        ['shipping_address']
     78                                                       }))
    8679                                      }),
    8780                            me = this;
     
    9184
    9285                                me.trigger('xhr__always__rainbow_pay_press__submit', {
    93                                                success: objData && objData.success
     86                                               errors:       objData && objData['errors'],
     87                                               success:      objData && objData['success'],
     88                                               transaction:  objData && objData['transaction'],
     89                                               disallowed_reason:
     90                                                             objData && objData['disallowed_reason']
    9491                                           });
    9592                            });
  • rainbowpaypress/trunk/js/le_requirejs/public/model_orig__app_public.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/public/model_orig__app_public.js
  • rainbowpaypress/trunk/js/le_requirejs/public/model_orig__fields.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/public/model_orig__fields.js
  • rainbowpaypress/trunk/js/le_requirejs/public/view_agg__div__transaction.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/public/view_agg__div__transaction.js
     
    3535define(['backbone',
    3636        'jquery',
     37        'util',
    3738        'public/model_info__stripe_checkout',
    3839        'public/model_info__transaction_details',
     
    4142    ], function(backbone,
    4243                $,
     44                util,
    4345                model_info__stripe_checkout,
    4446                ModelInfo_TransactionDetails,
     
    5456                //  @param  params.name                 Name of the seller
    5557                //  @param  params.desc                 Product description
     58                //  @param  params.handle               Item handle.
    5659                //  @param  params.info                 Miscellaneous additional information
    5760                initialize: function(params) {
     
    7275                                            'type':                 params.type,
    7376                                            'charge_description':   params.desc,
    74                                             'charge_amount':        params.amount
     77                                            'charge_amount':        params.amount,
     78                                            'handle':               params.handle
    7579                                        });
    7680
     
    99103                                                                   });
    100104                                        this.$el.text(
    101                                             "Your transaction has been submitted successfully.  Your confirmation code is: "
    102                                               + model_info__transaction_details.get('stripe_token_id'))
     105                                            "Your transaction has been submitted successfully on: "
     106                                              + util.getDateRepr(
     107                                                        util.parseDate(
     108                                                                event.transaction['created']))
     109                                              + "  Your confirmation code is: "
     110                                              + model_info__transaction_details
     111                                                                          .get('stripe_token_id'))
    103112                                                .append('<br>')
    104113                                                .append($buttonAnotherTransaction);
     114                                    } else {
     115                                        if (event.errors &&
     116                                            event.errors.indexOf('error__item_disallowed') >= 0) {
     117
     118                                            var strErrorDisallowed =
     119                                                  "Your transaction could not be submitted because this item has been marked as disallowed for purchase.";
     120
     121                                            if (event.disallowed_reason) {
     122                                                strErrorDisallowed += "Disallowed reason: ";
     123                                                strErrorDisallowed += event.disallowed_reason;
     124                                            }
     125
     126                                            window.alert(strErrorDisallowed);
     127                                            return;
     128                                        }
     129
     130                                        var strError =
     131                                              "Your transaction could not be submitted due to server-side error(s).  Contact support.";
     132
     133                                        if (event.errors) {
     134                                            strError += "  Actual errors reported: ";
     135                                            strError += event.errors.join(' ');
     136                                        }
     137
     138                                        window.alert(strError);
    105139                                    }
    106140                                });
  • rainbowpaypress/trunk/js/le_requirejs/public/view_agg__table__transaction_details.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/public/view_agg__table__transaction_details.js
     
    5454                        ViewAgg_Table.prototype.initialize.apply(this, arguments);
    5555
     56                        this.$el.addClass('widget_view_agg__table__transaction_details');
     57
     58
    5659                        var model_info__transaction_details  = params
    5760                                                                 .model_info__transaction_details,
     
    5962
    6063                        (new ViewAgg_Tr_TransactionDetail({
    61                                     model_info__transaction_details: model_info__transaction_details,
     64                                    model_info__details_base: model_info__transaction_details,
    6265                                    field: 'type',
    6366                                    name: "Stripe transaction type:"
     
    6568
    6669                        (new ViewAgg_Tr_TransactionDetail({
    67                                     model_info__transaction_details: model_info__transaction_details,
     70                                    model_info__details_base: model_info__transaction_details,
    6871                                    field: 'charge_description',
    6972                                    name: "Description:"
     
    7982                        (new ViewAgg_Tr_TransactionDetail({
    8083                                    callback_format_value: util.formatCurrency,
    81                                     model_info__transaction_details: model_info__transaction_details,
     84                                    model_info__details_base: model_info__transaction_details,
    8285                                    field: 'charge_amount',
    8386                                    name: "Puchase amount:"
     
    9093                                name: "Stripe token id:",
    9194                                name_seller: params.name,
    92                                 text_enter: "Enter credit card info",
    93                                 text_modify: "Modify"
     95                                text_enter: "Enter credit card info...",
     96                                text_modify: "Modify..."
    9497                            })).$el.appendTo(this.$el);
    9598
     
    100103                                name: "Stripe card email:",
    101104                                name_seller: params.name,
    102                                 text_enter: "Enter credit card info",
    103                                 text_modify: "Modify"
     105                                text_enter: "Enter credit card info...",
     106                                text_modify: "Modify..."
    104107                            })).$el.appendTo(this.$el);
    105108
    106109                        (new ViewAgg_Tr_TransactionDetail({
    107                                 model_info__transaction_details:
     110                                model_info__details_base:
    108111                                            model_info__transaction_details,
    109112                                field: 'customer_name',
    110113                                name: "Customer name:",
    111                                 text_enter: "Enter customer name",
    112                                 text_modify: "Modify"
     114                                text_enter: "Enter customer name...",
     115                                text_modify: "Modify..."
    113116                            })).$el.appendTo(this.$el);
    114117
    115118                        if (model_orig__fields.get('flag_query_phone')) {
    116119                            (new ViewAgg_Tr_TransactionDetail({
    117                                     model_info__transaction_details:
     120                                    model_info__details_base:
    118121                                                    model_info__transaction_details,
    119122                                    field: 'customer_phone',
    120123                                    name: "Customer phone:",
    121                                     text_enter: "Enter customer phone",
    122                                     text_modify: "Modify"
     124                                    text_enter: "Enter customer phone...",
     125                                    text_modify: "Modify..."
    123126                                })).$el.appendTo(this.$el);
    124127                        }
     
    126129                        if (model_orig__fields.get('flag_query_shipping')) {
    127130                            (new ViewAgg_Tr_TransactionDetail({
    128                                     model_info__transaction_details:
     131                                    model_info__details_base:
    129132                                                model_info__transaction_details,
    130133                                    field: 'shipping_address',
    131134                                    name: "Shipping address:",
    132                                     text_enter: "Enter shipping address",
    133                                     text_modify: "Modify"
     135                                    text_enter: "Enter shipping address...",
     136                                    text_modify: "Modify..."
    134137                                })).$el.appendTo(this.$el);
    135138                        }
    136139
    137140
    138                         var $buttonSubmit = $('<button>').text("Submit").appendTo(this.$el);
     141                        var $buttonSubmit = $('<button>').text("Submit");
    139142
    140143                        $('<tr>').append($('<td>').attr('colspan', '2').append($buttonSubmit))
     
    184187
    185188                                if (model_info__transaction_details
    186                                          .doCheckForFieldsWithMissingValues(model_orig__fields)) {
     189                                         .doCheckForFieldsWithMissingValues(
     190                                                                    model_orig__fields
     191                                                                          .getFieldsRequired())) {
    187192                                    window.alert("Please specify the required information by clicking on the links in red.");
    188193                                    return;
  • rainbowpaypress/trunk/js/le_requirejs/public/view_agg__tr__transaction_detail.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/admin/view_agg__tr__transaction_detail.js
     
    3434
    3535
    36 define(['backbone',
    37         'jquery'
    38     ], function (backbone, $) {
     36define(['view_agg__tr__detail_base'], function (ViewAgg_Tr_DetailBase) {
    3937
    40         return backbone.View.extend({
    41                 tagName: 'tr',
     38        return ViewAgg_Tr_DetailBase.extend({
    4239
    4340                //  @param  params.callback_format_value
    4441                //                                  Optional value formatting callback.
    45                 //  @param  params.model_info__transaction_details
     42                //  @param  params.model_info__details_base
    4643                //  @param  params.field
    4744                //  @param  params.name             The name of this detail.
     
    5249                //                                  value.
    5350                initialize: function(params) {
    54                         this.$el.addClass('widget_view_agg__tr__transaction_detail');
    5551
    56                         var $aModify = params.text_enter
    57                                      ? $('<a>').attr('href', '#')
    58                                      : null;
     52                        ViewAgg_Tr_DetailBase.prototype.initialize.apply(this, arguments);
    5953
    6054
    61                         this.get$aModify = function() {
    62                                 return $aModify;
    63                             };
    64 
    65 
    66                         var $divValue = $('<div>');
    67 
    68                         var $tdValue = $("<td width='66%'>").append(params.text
    69                                                                     ? $('<span>').text(params.text)
    70                                                                     : null)
    71                                                             .append($divValue);
    72 
    73 
    74                         var $divBottom = $('<div>').appendTo($tdValue);
    75 
    76                         this.get$divBottom = function() {
    77                                 return $divBottom;
    78                             };
    79 
    80 
    81                         if ($aModify) $aModify.appendTo($divBottom);
    82 
    83                         this.$el.append($("<td width='34%'>").text(params.name))
    84                                 .append($tdValue);
    85 
    86                         if ($aModify) {
    87                             var me = this;
    88 
    89                             $aModify.click(function(event) {
    90                                     event.preventDefault();
    91 
    92                                     me.trigger('click_modify');
    93                                 });
    94                         }
    95 
    96 
    97                         var field                      = params.field,
    98                             model_info__transaction_details  = params.model_info__transaction_details;
    99 
    100                         if (model_info__transaction_details) {
    101                             this.on('click_modify', function() {
    102                                     model_info__transaction_details.trigger('do_prompt', {field: field});
    103                                 }, this);
    104                         }
    105 
    106                         function _updateValue() {
    107                             var value = model_info__transaction_details.get(field);
    108 
    109                             if (params.callback_format_value) {
    110                                 value = params.callback_format_value(value);
    111                             }
    112 
    113                             $divValue.text(value || "");
    114 
    115                             if ($aModify) {
    116                                 $aModify.text(value ? params.text_modify || params.text_enter
    117                                                     : params.text_enter);
    118                                 if (value) {
    119                                     $aModify.css('color', "");
    120                                 }
    121                             }
    122                         }
    123 
    124                         if (model_info__transaction_details) {
    125                             _updateValue.call(this);
    126 
    127                             this.listenTo(model_info__transaction_details,
    128                                           'change:' + field,
    129                                           _updateValue);
    130 
    131                             this.listenTo(
    132                                 model_info__transaction_details,
    133                                 'fields_with_missing_values',
    134                                 function(event) {
    135                                     if ($aModify && event.fields.indexOf(field) >= 0) {
    136                                         $aModify.css('color', 'red');
    137                                     }
    138                                 });
    139                         }
     55                        this.$el.addClass('widget_view_agg__tr__transaction_detail');
    14056                    }
    14157            });
  • rainbowpaypress/trunk/js/le_requirejs/public/view_agg__tr__transaction_detail__stripe.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/admin/view_agg__tr__transaction_detail__stripe.js
     
    4545                //  @param  params.name_seller                          Name of the seller
    4646                initialize: function(params) {
    47                         ViewAgg_Tr_TransactionDetail.prototype.initialize.apply(this, arguments);
     47                        ViewAgg_Tr_TransactionDetail.prototype.initialize.call(this, {
     48                                model_info__details_base:   params &&
     49                                                            params.model_info__transaction_details,
     50                                field:                      params &&
     51                                                            params.field,
     52                                name:                       params &&
     53                                                            params.name,
     54                                name_seller:                params &&
     55                                                            params.name_seller,
     56                                text_enter:                 params &&
     57                                                            params.text_enter,
     58                                text_modify:                params &&
     59                                                            params.text_modify
     60                            });
    4861
    4962
  • rainbowpaypress/trunk/js/le_requirejs/underscore-private.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/underscore-private.js
  • rainbowpaypress/trunk/js/le_requirejs/util.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/util.js
     
    4545            }
    4646
    47             var strCents = "" + amount % 100;
     47            var amountAbs = window.Math.abs(amount);
     48
     49            var strCents = "" + amountAbs % 100;
    4850            if (strCents.length == 1) strCents = '0' + strCents;
    4951
    50             return '$' + _formatDollars(Math.floor(amount / 100)) + '.' + strCents;
     52            return (amount < 0 ? '-' : "") + '$'
     53                                           + _formatDollars(Math.floor(amountAbs / 100))
     54                                           + '.' + strCents;
     55        }
     56
     57        function _getDigits(num, len) {
     58            var str = "" + num;
     59            while (str.length < len) {
     60                str = '0' + str;
     61            }
     62            return str;
     63        }
     64
     65        function _getDateComponents(date) {
     66            if (!date) return null;
     67
     68            return {
     69                    year:   date.getFullYear(),
     70                    month:  _getDigits(date.getMonth() + 1, 2),
     71                    day:    _getDigits(date.getDate(), 2),
     72                    hour:   _getDigits(date.getHours(), 2),
     73                    min:    _getDigits(date.getMinutes(), 2),
     74                    sec:    _getDigits(date.getSeconds(), 2),
     75                    msec:   _getDigits(date.getMilliseconds(), 3)
     76                };
     77        }
     78
     79        function _getDateReprTZName(date) {
     80            var arrMatchTZ = date && date.toString().match(/\([^)]+\)/g);
     81            return arrMatchTZ && arrMatchTZ.length == 1 && arrMatchTZ[0] || "";
     82        }
     83
     84        function _getDateStrings(date) {
     85
     86            var date_components = _getDateComponents(date);
     87            if (!date_components) return null;
     88
     89            function _getWeekday() {
     90                return (['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'])[date.getDay()];
     91            }
     92
     93            return {
     94                    'weekday':  _getWeekday(),
     95                    'date':     date_components.year + '-' + date_components.month
     96                                                     + '-' + date_components.day,
     97                    'time':     date_components.hour + ':' + date_components.min
     98                                                     + ':' + date_components.sec,
     99                    'tz':       _getDateReprTZName(date)
     100                };
     101        }
     102
     103        //  This will parse a date string in the format "2016-04-03 05:10:41" that is assumed to
     104        //  be in UTC time.
     105        function _parseDate(strDate) {
     106            if (!strDate) return null;
     107
     108            var arrParts = strDate.split(' ');
     109            return new Date(arrParts[0] + 'T' + arrParts[1] + 'Z');
    51110        }
    52111
    53112        return {
    54                 formatCurrency: _formatCurrency
     113                formatCurrency:  _formatCurrency,
     114                getDateStrings:  _getDateStrings,
     115                parseDate:       _parseDate,
     116
     117
     118                getDateRepr: function(date) {
     119
     120                        var date_strings = _getDateStrings(date);
     121                        if (!date_strings) return null;
     122
     123                        return date_strings.weekday + ' ' + date_strings.date
     124                                                    + ' ' + date_strings.time
     125                                                    + ' ' + date_strings.tz;
     126                    }
    55127            };
    56128    });
  • rainbowpaypress/trunk/js/le_requirejs/view_agg__table.js

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/js/le_requirejs/view_agg__table.js
     
    4040                initialize: function() {
    4141
    42                         this.$el.attr({'border':       '0',
     42                        this.$el.addClass('widget_view_agg__table plugin_rainbow_payment_press')
     43                                .attr({'border':       '0',
    4344                                       'cellspacing':  '0',
    4445                                       'cellpadding':  '0'});
  • rainbowpaypress/trunk/readme.txt

    r1385818 r1391844  
    44Requires at least: 3.8.1
    55Tested up to: 4.4.2
    6 Stable tag: 2.3.0
     6Stable tag: 3.0.0
    77License: GPLv3
    88License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    5050  Currently only USD are supported.
    5151
     52  Demo at: http://maratbn.com/projects/rainbow-pay-press/#demo
     53
    5254Technical summary and special considerations:
    5355
     
    8082  https://wordpress.org/plugins/rainbowpaypress
    8183  https://github.com/maratbn/RainbowPayPress
     84  http://maratbn.com/projects/rainbow-pay-press
    8285
    8386
     
    128131== Changelog ==
    129132
     133= 3.0.0 =
     134* Fixed another date parsing bug that effected Firefox.
     135* Database schema has been modified.  Table 'plugin_rainbow_pay_press_transactions' fields
     136  'customer_name' and 'customer_phone' are now allowed to be NULL.  If upgrading, user should
     137  examine the table schema to verify that these fields are now allowed to be NULL, and if not,
     138  alter the table manually to allow these fields to be NULL.  User can use the Adminer plugin to
     139  accomplish this.  Alternatively, user can disable the plugin, backup the data in the table,
     140  delete the table, and re-enable the plugin to create the table anew.
     141* Entity name is now specified in the global RainbowPayPress configuration rather than in each
     142  shortcode.
     143* Fixed bug with resetting configuration settings to empty strings.
     144* Shortcode syntax has changed.  Instead of specifying the cost amount and description of each item
     145  in the shortcode, now only a pre-configured item handle is specified.  Upon upgrading, users will
     146  need to manually create the appropriate item records in the Items configuration, and to update
     147  their shortcodes to include handles to their items.
     148* Shortcode syntax has changed.  The previous shortcode parameter 'fields' has been renamed to
     149  'override_fields'.  Upon upgrading, users will need to manually modify their shortcodes to comply
     150  with this latest parameter name.
     151
    130152= 2.3.0 =
    131153* For better reliability and better server-side performance, loading the plugin's JavaScript logic
  • rainbowpaypress/trunk/style.css

    r1385818 r1391844  
    55  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    66
    7   Version:        2.4.0-development_unreleased
     7  Version:        3.1.0-development_unreleased
    88
    99  Module:         rainbowpaypress/style.css
     
    3030
    3131
     32.plugin_rainbow_payment_press.widget_view_agg__table td {
     33    margin-right: 1em;
     34}
     35.plugin_rainbow_payment_press.widget_view_agg__table td:last-child {
     36    margin-right: 0em;
     37}
     38
     39
     40.widget_view_agg__button__add_new_item {
     41    font-weight: bold;
     42}
     43
     44.widget_view_agg__table__items th,
     45.widget_view_agg__table__items td,
    3246.widget_view_agg__table__transactions th,
    3347.widget_view_agg__table__transactions td {
    3448    padding: 2px 5px;
    3549}
     50
     51
     52.widget_view_agg__table__items .item--even,
     53.widget_view_agg__table__transactions .transaction--even {
     54    background-color: #eee;
     55}
     56.widget_view_agg__table__items .item--odd,
     57.widget_view_agg__table__transactions .transaction--odd {
     58    background-color: #ddd;
     59}
Note: See TracChangeset for help on using the changeset viewer.