Plugin Directory

Changeset 3319619


Ignore:
Timestamp:
06/30/2025 12:12:23 AM (9 months ago)
Author:
idokd
Message:

Update to version 2.4.1 from GitHub

Location:
simple-payment
Files:
256 added
28 edited
1 copied

Legend:

Unmodified
Added
Removed
  • simple-payment/tags/2.4.1/addons/gravityforms/init.php

    r3318371 r3319619  
    573573
    574574    public function return_url( $form_id, $lead_id ) {
    575         // Lets use wordpress built-in function site_url
    576         /*$pageURL = GFCommon::is_ssl() ? 'https://' : 'http://';
    577         $server_port = apply_filters( 'gform_simplepayment_return_url_port', $_SERVER['SERVER_PORT'] );
    578         if ( $server_port != '80' && $server_port != 443) {
    579             $pageURL .= $_SERVER['SERVER_NAME'] . ':' . $server_port . $_SERVER['REQUEST_URI'];
    580         } else {
    581             $pageURL .= $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    582         }*/
    583575        $pageURL = site_url( $_SERVER[ 'REQUEST_URI' ] );
    584576        $ids_query = "ids={$form_id}|{$lead_id}";
     
    793785         * @param array $entry           The entry object currently being processed.
    794786         */
    795         $params[ 'redirect_url' ] = get_bloginfo( 'url' ) . '/?page=gf_simplepayment_ipn&entry_id=' . $entry[ 'id' ] . '&redirect_url=' . urlencode($this->return_url( $form[ 'id' ], $entry[ 'id' ] ) ) . ( isset( $params[ 'target' ] ) && $params[ 'target' ] ? '&target=' . $params[ 'target' ] : '' );
     787        $params[ 'redirect_url' ] = get_bloginfo( 'url' ) . '/?page=gf_simplepayment_ipn&entry_id=' . $entry[ 'id' ] . '&redirect_url=' . urlencode( $this->return_url( $form[ 'id' ], $entry[ 'id' ] ) ) . ( isset( $params[ 'target' ] ) && $params[ 'target' ] ? '&target=' . $params[ 'target' ] : '' );
    796788        $this->add_sp_pre_process( $feed, $submission_data, $form, $entry );
    797789        $params = apply_filters( 'gform_simplepayment_args_before_payment', $params, $form[ 'id' ], $submission_data, $feed, $entry );
  • simple-payment/tags/2.4.1/admin/admin.php

    r3318371 r3319619  
    5656            }
    5757        }
    58         add_action( 'admin_menu', [ $this, 'add_plugin_options_page' ] );
     58        //add_action( 'admin_menu', [ $this, 'add_plugin_options_page' ] );
    5959        if ( !empty( $GLOBALS[ 'pagenow' ] ) ) {
    6060            switch ( $GLOBALS[ 'pagenow' ] ) {
     
    6868            }
    6969        }
     70
     71        $_active_plugins = array_merge( is_multisite() ? array_keys( get_site_option( 'active_sitewide_plugins', [] ) ) : [], get_option( 'active_plugins', [] ) );
     72        //if ( in_array( 'admin-columns-pro/admin-columns-pro.php', $_active_plugins ) ) {
     73        //  add_action( 'after_setup_theme', function () {
     74        //      require_once( SPWP_PLUGIN_DIR . '/addons/admin-columns-pro/init.php' );
     75        //  } );
     76        //}
     77
     78        add_action( 'admin_enqueue_scripts', function () {
     79            wp_enqueue_script( 'simple-payment-admin-js', plugin_dir_url( __FILE__ ) . 'script.js', [], false, true );
     80            wp_enqueue_style( 'simple-payment-admin-css', plugin_dir_url( __FILE__ ) . 'style.css', [], false );
     81        } );
     82
     83        add_action( 'admin_init', [ $this, 'register_license_settings' ] );
     84        //add_action( 'sp_admin_tabs', [ $this, 'add_plugin_settings' ] );
     85        //add_filter( 'sp_admin_sections', [ $this, 'add_plugin_settings' ] );
    7086    }
    7187
     
    177193          'simple-payments',
    178194          [ $this, 'render_transactions' ],
    179           plugin_dir_url( __FILE__ ) . 'assets/simple-payment-icon.png',
     195          SPWP_PLUGIN_URL . 'assets/simple-payment-icon.png',
    180196          30
    181197      );
     
    463479        ] );
    464480        require( SPWP_PLUGIN_DIR.'/admin/transaction-list-table.php' );
    465         $list = new Transaction_List();
     481        $list =  new Transaction_List(); // Consider using different List when using ACP - did_action( 'acp/ready' );
    466482    }
    467483
  • simple-payment/tags/2.4.1/admin/style.css

    r2176343 r3319619  
    11.ttablenav .alignleft:nth-of-type(2n) { clear: both; }
    2 pre.json {}
    32pre.json .string { color: green; }
    43pre.json .number { color: darkorange; }
     
    76pre.json .key { color: red; }
    87pre.url { word-break: break-all; white-space: pre-wrap; }
     8.transaction-overview {
     9    display: flex;
     10    flex-wrap: wrap;
     11    row-gap: 5px;
     12    column-gap: 5px;
     13    justify-content: space-between;
     14}
     15.transaction-item {
     16    padding: 5px;
     17    display: flex;
     18    justify-content: space-between;
     19    flex-grow: 1;
     20    order: 0;
     21    row-gap: 5px;
     22    column-gap: 5px;
     23}
     24
     25.transaction-item.item-parameters {
     26    order: 100;
     27}
     28
     29.transaction-item.item-redirect_url, .transaction-item.item-parameters, .transaction-item.item-user_agent {
     30    flex-basis: 100%;
     31    flex-direction: column;
     32}
  • simple-payment/tags/2.4.1/admin/transaction-list-table.php

    r3318406 r3319619  
    352352    } else {
    353353      $screen = get_current_screen();
     354      //print_r(  $screen );
    354355      $per_page = get_user_meta(get_current_user_id(), $screen->get_option('per_page', 'option'), true);
    355356      $per_page = $per_page ? $per_page : $this->get_items_per_page( 'per_page', $screen->get_option('per_page', 'default'));
  • simple-payment/tags/2.4.1/admin/transaction-log.php

    r2448085 r3319619  
    1313    ?>
    1414    <hr class="wp-header-end">
     15    <div class="transaction-overview">
     16    <?php
     17    $payment = SimplePaymentPlugin::instance()->fetch( $_REQUEST[ 'id' ] );
     18    foreach( $payment as $key => $value ) {
     19        if ( ! empty( $value ) ) {
     20            echo '<div class="transaction-item item-' . $key . '"><strong>' . esc_html( ucfirst( $key ) ) . ':</strong> ' . ( !is_array( $value ) ? esc_html( $value ) : '<pre class="json">' . json_encode( $value ) . '</pre>' ) . '</div>';
     21        }
     22    }
     23    ?>
     24    </div>
    1525    <?php $list->views(); ?>
    1626    <form id="transaction-logs-filter" method="get">
  • simple-payment/tags/2.4.1/engines/cardcom.php

    r3318371 r3319619  
    1616}, 1000, 2 );
    1717
     18/*
    1819add_filter( 'sp_payment_callback', function( $url ) {
    1920    global $SPWP;
    20     if ( !$SPWP::param( 'cardcom.short_urls' ) ) return;
     21    if ( !$SPWP::param( 'cardcom.short_urls' ) ) return( $url );
    2122    $uid = wp_generate_uuid4();
    2223    set_transient( 'sp_' . $uid, $url ); // TODO: should we define expiration/ 5 days?
    23     $url = add_query_arg( [
    24         $SPWP::OP => $SPWP::OPERATION_REDIRECT,
    25         '_spr' => $uid
    26     ], site_url() );
     24    //$url = add_query_arg( [
     25    //  $SPWP::SPRD => $SPWP::OPERATION_REDIRECT,
     26    //  '_spr' => $uid
     27    //], site_url() );
    2728    return( $url );
    2829}, 5000  );
     30*/
     31
     32add_filter( 'gform_simplepayment_return_url', function( $url, $form_id, $lead_id ) {
     33    global $SPWP;
     34    if ( !$SPWP::param( 'cardcom.short_urls' ) ) return( $url );
     35    $pageURL = site_url( '/_gf-sp' );
     36    $ids_query = "ids={$form_id}|{$lead_id}";
     37    $ids_query .= '&hash=' . wp_hash( $ids_query );
     38    $url = remove_query_arg( 'gf_simplepayment_retry', $pageURL );
     39    $url = add_query_arg( 'gf_simplepayment_return', base64_encode( $ids_query ), $url );
     40    return( $url );
     41}, 50, 3 );
     42
    2943
    3044add_filter( 'sp_payment_callback', function( $callback ) {
  • simple-payment/tags/2.4.1/languages/simple-payment.pot

    r3318406 r3319619  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Simple Payment 2.3.9\n"
     5"Project-Id-Version: Simple Payment 2.4.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/simple-payment\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2025-06-26T17:29:54+00:00\n"
     12"POT-Creation-Date: 2025-06-30T00:08:12+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1414"X-Generator: WP-CLI 2.10.0\n"
     
    1717#. Plugin Name of the plugin
    1818#: simple-payment-plugin.php
     19#: addons/admin-columns-pro/classes/Service/ColumnGroup.php:20
     20#: addons/admin-columns-pro/classes/Service/ListScreens.php:19
    1921#: addons/elementor/widget.php:31
    2022#: addons/woocommerce/init.php:127
    2123#: addons/woocommerce/init.php:248
    2224#: addons/wpjobboard/config.php:8
    23 #: admin/admin.php:166
    24 #: admin/admin.php:167
     25#: admin/admin.php:182
     26#: admin/admin.php:183
    2527msgid "Simple Payment"
    2628msgstr ""
     
    445447msgstr ""
    446448
    447 #: addons/gravityforms/init.php:987
     449#: addons/gravityforms/init.php:979
    448450msgid "Payment Completed"
    449451msgstr ""
    450452
    451 #: addons/gravityforms/init.php:988
     453#: addons/gravityforms/init.php:980
    452454msgid "Payment Failed"
    453455msgstr ""
    454456
    455 #: addons/gravityforms/init.php:989
     457#: addons/gravityforms/init.php:981
    456458msgid "Subscription Created"
    457459msgstr ""
    458460
    459 #: addons/gravityforms/init.php:1389
     461#: addons/gravityforms/init.php:1381
    460462#: addons/woocommerce/init.php:206
    461463#: templates/form-woocommerce.php:65
     
    682684msgstr ""
    683685
    684 #: admin/admin.php:86
     686#: admin/admin.php:102
    685687msgid "Thanks for updating Simple Payment, you can checkout for new features and updates <a href=\"https://simple-payment.yalla-ya.com\" target=\"_blank\">here</a>."
    686688msgstr ""
    687689
    688 #: admin/admin.php:90
     690#: admin/admin.php:106
    689691msgid "Thanks for installing Simple Payment, after your test our plugin, dont forget to get your license to process real transactions, you can do it <a href=\"https://simple-payment.yalla-ya.com\" target=\"_blank\">here</a>."
    690692msgstr ""
    691693
    692 #: admin/admin.php:116
     694#: admin/admin.php:132
    693695msgid "View Simple Payment documentation"
    694696msgstr ""
    695697
    696 #: admin/admin.php:116
     698#: admin/admin.php:132
    697699msgid "Docs"
    698700msgstr ""
    699701
    700 #: admin/admin.php:117
     702#: admin/admin.php:133
    701703msgid "Visit premium customer support"
    702704msgstr ""
    703705
    704 #: admin/admin.php:117
     706#: admin/admin.php:133
    705707msgid "Premium support"
    706708msgstr ""
    707709
    708 #: admin/admin.php:159
    709 #: admin/admin.php:356
     710#: admin/admin.php:175
     711#: admin/admin.php:372
    710712#: admin/settings.php:123
    711713#: settings.php:122
     
    713715msgstr ""
    714716
    715 #: admin/admin.php:174
    716 #: admin/admin.php:175
     717#: admin/admin.php:190
     718#: admin/admin.php:191
    717719#: admin/transaction-list-table.php:241
    718720msgid "Payments"
    719721msgstr ""
    720722
    721 #: admin/admin.php:185
    722 #: admin/admin.php:186
     723#: admin/admin.php:201
     724#: admin/admin.php:202
    723725msgid "Transaction Details"
    724726msgstr ""
    725727
    726 #: admin/admin.php:207
     728#: admin/admin.php:223
    727729msgid "Simple Payment Settings"
    728730msgstr ""
    729731
    730 #: admin/admin.php:243
     732#: admin/admin.php:259
    731733msgid "License Key"
    732734msgstr ""
    733735
    734 #: admin/admin.php:406
     736#: admin/admin.php:422
    735737msgid "Auto"
    736738msgstr ""
    737739
    738 #: admin/admin.php:541
     740#: admin/admin.php:557
    739741msgid "License key is required"
    740742msgstr ""
    741743
    742 #: admin/admin.php:566
     744#: admin/admin.php:582
    743745msgid "License is not valid on the current domain"
    744746msgstr ""
    745747
    746 #: admin/admin.php:574
     748#: admin/admin.php:590
    747749msgid "License has not been activated"
    748750msgstr ""
    749751
    750 #: admin/admin.php:579
     752#: admin/admin.php:595
    751753msgid "License key was not found"
    752754msgstr ""
    753755
    754 #: admin/admin.php:583
     756#: admin/admin.php:599
    755757msgid "Unhandled error:"
    756758msgstr ""
     
    19631965msgstr ""
    19641966
    1965 #: simple-payment-plugin.php:142
     1967#: simple-payment-plugin.php:144
    19661968msgid "Simple Payment License Error: %s"
    19671969msgstr ""
    19681970
    1969 #: simple-payment-plugin.php:142
     1971#: simple-payment-plugin.php:144
    19701972msgid "License error, or no license."
    19711973msgstr ""
    19721974
    1973 #: simple-payment-plugin.php:188
     1975#: simple-payment-plugin.php:190
    19741976msgid "Every %s Minutes"
    19751977msgstr ""
    19761978
    1977 #: simple-payment-plugin.php:584
     1979#: simple-payment-plugin.php:587
    19781980msgid "Error payment recharge"
    19791981msgstr ""
    19801982
    1981 #: simple-payment-plugin.php:833
     1983#: simple-payment-plugin.php:836
    19821984msgid "Couldn't update transaction: %s"
    19831985msgstr ""
  • simple-payment/tags/2.4.1/readme.txt

    r3318406 r3319619  
    44Tags: credit card, simple payment, donation, membership, checkout, payment request, payment gateway, sales, woocommerce, store, ecommerce, e-commerce, commerce, gutenberg, elementor, cardcom, icount, icredit, payme, isracard, paypal
    55Requires at least: 4.6
    6 Tested up to: 6.6.2
    7 Stable tag: 2.4.0
     6Tested up to: 6.8.1
     7Stable tag: 2.4.1
    88Requires PHP: 5.4
    99License: GPLv2 or later
     
    9393== Changelog ==
    9494
    95 = 2.3.10 =
     95= 2.4.2 =
     96*Release Date - 29 Jun 2025*
     97* Better support for Cardcom & GravityForms
     98* Security fixes
     99
     100= 2.4.1 =
    96101*Release Date - 26 Jun 2025*
    97102* Security fix, XSS on admin.
    98 
    99 = 2.3.9 =
    100 *Release Date - 26 Jun 2025*
    101103* Security and bug fixes
    102104* Performance Improvment - Seperation of Front-end / Backend code
    103105* Fixing issue with Woocommerce Subscriptions forcing tokens on Woocommerce Checkout
    104106* Feature: shorten urls when Payment Gateway cannot handle standard url lengths
     107* Tested under PHP 8.4
    105108
    106109= 2.2.2 =
  • simple-payment/tags/2.4.1/simple-payment-plugin.php

    r3318406 r3319619  
    44 * Plugin URI: https://simple-payment.yalla-ya.com
    55 * Description: Simple Payment enables integration with multiple payment gateways, and customize multiple payment forms.
    6  * Version: 2.4.0
     6 * Version: 2.4.1
    77 * Author: Ido Kobelkowsky / yalla ya!
    88 * Author URI: https://github.com/idokd
     
    4545
    4646    public static $table_name = 'sp_transactions';
     47    public static $table_name_metadata = 'sp_transactions_metadata';
     48   
    4749    public static $engines = [ 'PayPal', 'Cardcom', 'iCount', 'PayMe', 'iCredit', 'CreditGuard', 'Meshulam', 'YaadPay', 'Credit2000', 'Custom' ];
    4850
     
    275277        $status = false;
    276278        if ( $code = parent::status( array_merge( $data, $params ) ) ) {
     279            $params[ 'confirmation_code' ] = $code;
    277280            $status = self::update( $this->payment_id ? : $this->engine->transaction, [
    278281                'status' => self::TRANSACTION_SUCCESS,
     
    838841    }
    839842
     843    public function get_entry(  $id, $engine = null ){
     844        return( $this->fetch( $id, $engine ) );
     845    }
    840846
    841847    public function fetch( $id, $engine = null ) {
     
    10301036require_once( 'addons/gravityforms/init.php' );
    10311037
    1032 
    10331038//require_once('addons/recaptcha/init.php');
    10341039
  • simple-payment/tags/2.4.1/vendor/autoload.php

    r3318371 r3319619  
    1515        }
    1616    }
    17     trigger_error(
    18         $err,
    19         E_USER_ERROR
    20     );
     17    throw new RuntimeException($err);
    2118}
    2219
  • simple-payment/tags/2.4.1/vendor/composer/InstalledVersions.php

    r3318371 r3319619  
    2828{
    2929    /**
     30     * @var string|null if set (by reflection by Composer), this should be set to the path where this class is being copied to
     31     * @internal
     32     */
     33    private static $selfDir = null;
     34
     35    /**
    3036     * @var mixed[]|null
    3137     * @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}|array{}|null
    3238     */
    3339    private static $installed;
     40
     41    /**
     42     * @var bool
     43     */
     44    private static $installedIsLocalDir;
    3445
    3546    /**
     
    310321        self::$installed = $data;
    311322        self::$installedByVendor = array();
     323
     324        // when using reload, we disable the duplicate protection to ensure that self::$installed data is
     325        // always returned, but we cannot know whether it comes from the installed.php in __DIR__ or not,
     326        // so we have to assume it does not, and that may result in duplicate data being returned when listing
     327        // all installed packages for example
     328        self::$installedIsLocalDir = false;
     329    }
     330
     331    /**
     332     * @return string
     333     */
     334    private static function getSelfDir()
     335    {
     336        if (self::$selfDir === null) {
     337            self::$selfDir = strtr(__DIR__, '\\', '/');
     338        }
     339
     340        return self::$selfDir;
    312341    }
    313342
     
    323352
    324353        $installed = array();
     354        $copiedLocalDir = false;
    325355
    326356        if (self::$canGetVendors) {
     357            $selfDir = self::getSelfDir();
    327358            foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
     359                $vendorDir = strtr($vendorDir, '\\', '/');
    328360                if (isset(self::$installedByVendor[$vendorDir])) {
    329361                    $installed[] = self::$installedByVendor[$vendorDir];
     
    331363                    /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
    332364                    $required = require $vendorDir.'/composer/installed.php';
    333                     $installed[] = self::$installedByVendor[$vendorDir] = $required;
    334                     if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
    335                         self::$installed = $installed[count($installed) - 1];
     365                    self::$installedByVendor[$vendorDir] = $required;
     366                    $installed[] = $required;
     367                    if (self::$installed === null && $vendorDir.'/composer' === $selfDir) {
     368                        self::$installed = $required;
     369                        self::$installedIsLocalDir = true;
    336370                    }
     371                }
     372                if (self::$installedIsLocalDir && $vendorDir.'/composer' === $selfDir) {
     373                    $copiedLocalDir = true;
    337374                }
    338375            }
     
    351388        }
    352389
    353         if (self::$installed !== array()) {
     390        if (self::$installed !== array() && !$copiedLocalDir) {
    354391            $installed[] = self::$installed;
    355392        }
  • simple-payment/tags/2.4.1/vendor/composer/installed.php

    r3318371 r3319619  
    44        'pretty_version' => 'dev-master',
    55        'version' => 'dev-master',
    6         'reference' => '8d70fa9f086df134f54cc8e70526cb888ea9b265',
     6        'reference' => '59fc00a8805a5e2566813aaee5fd97f5dada586c',
    77        'type' => 'project',
    88        'install_path' => __DIR__ . '/../../',
     
    7070            'pretty_version' => 'dev-master',
    7171            'version' => 'dev-master',
    72             'reference' => '8d70fa9f086df134f54cc8e70526cb888ea9b265',
     72            'reference' => '59fc00a8805a5e2566813aaee5fd97f5dada586c',
    7373            'type' => 'project',
    7474            'install_path' => __DIR__ . '/../../',
  • simple-payment/tags/2.4.1/vendor/yalla-ya/simple-payment/Engines/Cardcom.php

    r3318371 r3319619  
    77use DateInterval;
    88
    9 if (!defined("ABSPATH")) {
     9if (!defined("ABSPATH") ) {
    1010  exit; // Exit if accessed directly
    1111}
     
    4949  const OPERATIONS = [ 1 => 'Charge', 2 => 'Charge & Token', 3 => 'Token (Charge Pending)', 4 => 'Suspended Deal' ];
    5050  const DOC_TYPES = [ 1 => 'Invoice', 3 => 'Formal Receipt', 101 => 'Order Confirmation', 400 => 'Receipt' , 405 => 'Donation' ];
    51   const FIELD_STATUS = [ 'require' => 'Shown & Required', 'show' => 'Shown', 'hide' => 'Hidden'];
    52   const CREDIT_TYPES = [ 1 => 'Normal', 6 => 'Credit'];
    53   const DOC_OPERATIONS = [ 0 => 'No Invoice', 1 => 'Invoice', 2 => 'Forward (Do not show)'];
     51  const FIELD_STATUS = [ 'require' => 'Shown & Required', 'show' => 'Shown', 'hide' => 'Hidden' ];
     52  const CREDIT_TYPES = [ 1 => 'Normal', 6 => 'Credit' ];
     53  const DOC_OPERATIONS = [ 0 => 'No Invoice', 1 => 'Invoice', 2 => 'Forward (Do not show)' ];
    5454
    5555  public function __construct( $params = null, $handler = null, $sandbox = true ) {
     
    5959
    6060  public function process( $params ) {
    61     //header("Location: ".$params['url']);
     61    //header("Location: ".$params[ 'url' ]);
    6262    //return(true);
    6363    return( $params[ 'url' ] );
     
    7474      $post[ 'username' ] = $this->username;
    7575    }
    76     //$post['terminalnumber'] = $this->terminal;
    77     //$post['username'] = $this->username;
     76    //$post[ 'terminalnumber' ] = $this->terminal;
     77    //$post[ 'username' ] = $this->username;
    7878    $post[ 'lowprofilecode' ] = $this->transaction;
    7979    $post[ 'codepage' ] = 65001;
     
    106106        'transaction_id' => $this->transaction,
    107107        'url' => $this->api[ 'indicator_request' ],
    108         'status' => isset( $response[ 'OperationResponse' ] ) ? $response[ 'OperationResponse' ] : ( isset( $response[ 'DealResponse' ] ) ? $response[ 'DealResponse' ] : ''),
     108        'status' => isset( $response[ 'OperationResponse' ] ) ? $response[ 'OperationResponse' ] : ( isset( $response[ 'DealResponse' ] ) ? $response[ 'DealResponse' ] : '' ),
    109109        'description' => isset( $response[ 'OperationResponseText' ] ) ? $response[ 'OperationResponseText' ] : $response[ 'Description' ],
    110110        'request' => json_encode( $post ),
     
    117117    switch( intval( $operation ) ) {
    118118      case 1:
    119         $code = $response[ 'DealResponse' ];
    120         if ( isset( $response[ 'OperationResponse' ] ) && $response[ 'OperationResponse' ] == '0' && isset( $response[ 'DealResponse' ] ) && $response['DealResponse'] == '0' ) {
     119        $code = $response[ 'InternalDealNumber' ];
     120        if ( isset( $response[ 'OperationResponse' ] ) && $response[ 'OperationResponse' ] == '0' && isset( $response[ 'DealResponse' ] ) && $response[ 'DealResponse' ] == '0' ) {
    121121          $this->confirmation_code = $code;
    122122        }
     
    125125      case 2:
    126126        $code = $response[ 'TokenResponse' ];
    127         if ( isset( $response[ 'OperationResponse' ] ) && $response[ 'OperationResponse' ] == '0' && isset( $response[ 'DealResponse' ] ) && $response[ 'DealResponse' ] == '0' && isset( $response[ 'TokenResponse' ] ) && $response[ 'TokenResponse' ] == '0') {
     127        if ( isset( $response[ 'OperationResponse' ] ) && $response[ 'OperationResponse' ] == '0' && isset( $response[ 'DealResponse' ] ) && $response[ 'DealResponse' ] == '0' && isset( $response[ 'TokenResponse' ] ) && $response[ 'TokenResponse' ] == '0' ) {
    128128          $this->confirmation_code = $code;
    129129        }
     
    149149      'url' => ':callback',
    150150      'status' => isset( $params[ 'ResposeCode' ] ) ? $params[ 'ResposeCode' ] : $params[ 'ResponseCode' ],
    151       'description' => isset( $params[  'OperationResponseText' ] ) ? $params[  'OperationResponseText  '] : $params['Description'],
     151      'description' => isset( $params[  'OperationResponseText' ] ) ? $params[  'OperationResponseText  ' ] : $params[ 'Description' ],
    152152      'request' => json_encode( $params ),
    153153      'response' => null
     
    156156  }
    157157
    158   public function status($params) {
    159     parent::status($params);
    160     $this->transaction = $params['lowprofilecode'];
    161     $this->save([
     158  public function status( $params ) {
     159    parent::status( $params );
     160    $this->transaction = $params[ 'lowprofilecode' ];
     161    $this->save( [
    162162      'transaction_id' => $this->transaction,
    163       'url' => $_SERVER["REQUEST_URI"],
    164       'status' => isset($params['OperationResponse']) ? $params['OperationResponse'] : $params['DealResponse'],
    165       'description' => isset($params['OperationResponseText']) ? $params['OperationResponseText'] : $params['Description'],
    166       'request' => json_encode($_REQUEST),
     163      'url' => $_SERVER[ 'REQUEST_URI' ],
     164      'status' => isset( $params[ 'OperationResponse' ] ) ? $params[ 'OperationResponse' ] : $params[ 'DealResponse' ],
     165      'description' => isset( $params[ 'OperationResponseText' ] ) ? $params[ 'OperationResponseText' ] : $params[ 'Description' ],
     166      'request' => json_encode( $_REQUEST ),
    167167      'response' => null
    168     ]);
     168    ] );
    169169    $post = [];
    170170    if ( !$this->sandbox ) {
    171       $post['terminalnumber'] = $this->param_part($params);
    172       $post['username'] = $this->param_part($params, 'username');
     171      $post[ 'terminalnumber' ] = $this->param_part( $params );
     172      $post[ 'username' ] = $this->param_part( $params, 'username' );
    173173    } else {
    174       $post['terminalnumber'] = $this->terminal;
    175       $post['username'] = $this->username;
    176     }
    177     $post['lowprofilecode'] = $params['lowprofilecode'];
    178     $status = $this->post($this->api['indicator_request'], $post);
    179     parse_str($status, $status);
    180     //$this->transaction = $params['lowprofilecode'];
     174      $post[ 'terminalnumber' ] = $this->terminal;
     175      $post[ 'username' ] = $this->username;
     176    }
     177    $post[ 'lowprofilecode' ] = $params[ 'lowprofilecode' ];
     178    $status = $this->post( $this->api[ 'indicator_request' ], $post);
     179    parse_str( $status, $status );
     180    //$this->transaction = $params[ 'lowprofilecode' ];
    181181
    182182    // TODO: fetch VISA, YEAR, MONTH, ID???
     
    184184    if ( isset( $status[ 'Token' ] ) && $status[ 'Token' ] ) {
    185185      $token = [
    186           'token' => $status['Token'],
    187           SimplePayment::CARD_OWNER => $status['CardOwnerID'],
    188           SimplePayment::CARD_EXPIRY_YEAR => $status['CardValidityYear'],
    189           SimplePayment::CARD_EXPIRY_MONTH => $status['CardValidityMonth'],
     186          'token' => $status[ 'Token' ],
     187          SimplePayment::CARD_OWNER => $status[ 'CardOwnerID' ],
     188          SimplePayment::CARD_EXPIRY_YEAR => $status[ 'CardValidityYear' ],
     189          SimplePayment::CARD_EXPIRY_MONTH => $status[ 'CardValidityMonth' ],
    190190        //  'card_type' => '',
    191           'expiry' => $status['TokenExDate'],
     191          'expiry' => $status[ 'TokenExDate' ],
    192192      ];
    193193    }
    194194    $response = $status;
    195195    $this->confirmation_code = isset( $response[ 'InternalDealNumber' ] ) ? $response[ 'InternalDealNumber' ] : null;
    196     $this->save([
     196    $this->save( [
    197197      'transaction_id' => $this->transaction,
    198       'url' => $this->api['indicator_request'],
    199       'status' => isset($response['OperationResponse']) ? $response['OperationResponse'] : $response['DealResponse'],
    200       'description' => isset($response['OperationResponseText']) ? $response['OperationResponseText'] : $response['Description'],
    201       'request' => json_encode($post),
    202       'response' => json_encode($response),
     198      'url' => $this->api[ 'indicator_request' ],
     199      'status' => isset( $response[ 'OperationResponse' ] ) ? $response[ 'OperationResponse' ] : $response[ 'DealResponse' ],
     200      'description' => isset( $response[ 'OperationResponseText' ] ) ? $response[ 'OperationResponseText' ] : $response[ 'Description' ],
     201      'request' => json_encode( $post ),
     202      'response' => json_encode( $response ),
    203203      'token' => $token
    204     ]);
    205     if (!isset($response['OperationResponse']) || $response['OperationResponse'] != 0) {
    206       throw new Exception(isset($response['OperationResponseText']) ? $response['OperationResponseText'] : $response['Description'], isset($response['OperationResponse']) ? $response['OperationResponse'] : $response['DealResponse']);
    207     }
    208     if ($params['Operation'] == 2 && isset($params['payments']) && $params['payments'] == "monthly") {
    209       if ($this->param('recurr_at') == 'status' && $this->param('reurring') == 'provider') $this->recur_by_provider($params);
     204    ] );
     205    if ( !isset( $response[ 'OperationResponse' ]) || $response[ 'OperationResponse' ] != 0 ) {
     206      throw new Exception( isset( $response[ 'OperationResponseText' ] ) ? $response[ 'OperationResponseText' ] : $response[ 'Description' ], isset( $response[ 'OperationResponse' ] ) ? $response[ 'OperationResponse' ] : $response[ 'DealResponse' ] );
     207    }
     208    if ( $params[ 'Operation' ] == 2 && isset( $params[ 'payments' ] ) && $params[ 'payments' ] == 'monthly' ) {
     209      if ( $this->param( 'recurr_at' ) == 'status' && $this->param( 'reurring' ) == 'provider' ) $this->recur_by_provider( $params );
    210210    }
    211211    return( $this->confirmation_code );
     
    213213
    214214  public function post_process($params) {
    215     $this->transaction = isset( $_REQUEST['lowprofilecode'] ) ? $_REQUEST['lowprofilecode'] : $params[ 'transaction_id' ];
     215    $this->transaction = isset( $_REQUEST[ 'lowprofilecode' ] ) ? $_REQUEST[ 'lowprofilecode' ] : $params[ 'transaction_id' ];
    216216    $response = $_REQUEST;
    217217    $this->save([
    218218      'transaction_id' => $this->transaction,
    219219      'url' => ':post_process',
    220       'status' => isset($response['ResponseCode']) ? $response['ResponseCode'] : $response['response_code'],
    221       'description' => isset($response['Description']) ? $response['Description'] : null,
     220      'status' => isset($response[ 'ResponseCode' ]) ? $response[ 'ResponseCode' ] : $response[ 'response_code' ],
     221      'description' => isset($response[ 'Description' ]) ? $response[ 'Description' ] : null,
    222222      'request' => json_encode($params),
    223223      'response' => json_encode($response)
    224224    ]);
    225     if ($params['Operation'] == 2 && isset($params['payments']) && $params['payments'] == "monthly") {
    226       if ($this->param('recurr_at') == 'post' && $this->param('reurring') == 'provider') return($this->recur_by_provider($params));
     225    if ($params[ 'Operation' ] == 2 && isset($params[ 'payments' ]) && $params[ 'payments' ] == "monthly") {
     226      if ($this->param( 'recurr_at' ) == 'post' && $this->param( 'reurring' ) == 'provider' ) return($this->recur_by_provider($params) );
    227227    }
    228228    // TODO: update confirmation code con status
    229     //$this->confirmation_code = $response['confirmation_code'];
     229    //$this->confirmation_code = $response[ 'confirmation_code' ];
    230230    return( $_REQUEST[ 'ResponeCode' ] == 0 );
    231231  }
     
    254254    $post[ 'APILevel' ] = $this->api[ 'version' ];
    255255    if ( !$this->sandbox ) {
    256       $post[ 'TerminalNumber'] = $this->param_part( $params );
    257       $post[ 'UserName'] = $this->param_part( $params, 'username' );
    258       // $this->password = $this->param_part($params, 'password');
    259       // $post['Password'] = $this->password;
     256      $post[ 'TerminalNumber' ] = $this->param_part( $params );
     257      $post[ 'UserName' ] = $this->param_part( $params, 'username' );
     258      // $this->password = $this->param_part($params, 'password' );
     259      // $post[ 'Password' ] = $this->password;
    260260    } else {
    261261      $post[ 'TerminalNumber' ] = $this->terminal;
     
    271271
    272272
    273     $post['ProductName'] = $params['product'];
    274     $post['SumToBill'] = $params['amount'];
    275 
    276     if (isset($params[SimplePayment::CARD_OWNER]) && $params[SimplePayment::CARD_OWNER]) $post['CardOwnerName'] = $params[SimplePayment::CARD_OWNER];
    277     if (!isset($post['CardOwnerName']) && isset($params['full_name']) && $params['full_name']) $post['CardOwnerName'] = $params['full_name']; // card_holder
    278 
    279     if (isset($params['phone']) && $params['phone']) $post['CardOwnerPhone'] = $params['phone'];
    280     if (isset($params['email']) && $params['email']) $post['CardOwnerEmail'] = $params['email'];
    281 
    282     if (isset($params['payment_id']) && $params['payment_id']) $post['ReturnValue'] = $params['payment_id'];
    283 
    284     $post['codepage'] = 65001; // Codepage fixed to enable hebrew
    285     $currency = isset($params[SimplePayment::CURRENCY]) && $params[SimplePayment::CURRENCY] ? $params[SimplePayment::CURRENCY] : $this->param('currency');
    286     if ($currency) {
    287       if ($currency = self::CURRENCIES[$currency]) $post['CoinID'] = $currency;
    288       else throw new Exception('CURRENCY_NOT_SUPPORTED_BY_ENGINE', 500);
    289     }
    290 
    291     $language = isset($params['language']) ? $params['language'] : $this->param('language');
    292     if ($language != '') $post['Language'] = $language;
     273    $post[ 'ProductName' ] = $params[ 'product' ];
     274    $post[ 'SumToBill' ] = $params[ 'amount' ];
     275
     276    if (isset($params[SimplePayment::CARD_OWNER]) && $params[SimplePayment::CARD_OWNER]) $post[ 'CardOwnerName' ] = $params[SimplePayment::CARD_OWNER];
     277    if (!isset($post[ 'CardOwnerName' ]) && isset($params[ 'full_name' ]) && $params[ 'full_name' ]) $post[ 'CardOwnerName' ] = $params[ 'full_name' ]; // card_holder
     278
     279    if (isset($params[ 'phone' ]) && $params[ 'phone' ]) $post[ 'CardOwnerPhone' ] = $params[ 'phone' ];
     280    if (isset($params[ 'email' ]) && $params[ 'email' ]) $post[ 'CardOwnerEmail' ] = $params[ 'email' ];
     281
     282    if (isset($params[ 'payment_id' ]) && $params[ 'payment_id' ]) $post[ 'ReturnValue' ] = $params[ 'payment_id' ];
     283
     284    $post[ 'codepage' ] = 65001; // Codepage fixed to enable hebrew
     285    $currency = isset( $params[ SimplePayment::CURRENCY ] ) && $params[ SimplePayment::CURRENCY ] ? $params[ SimplePayment::CURRENCY ] : $this->param( 'currency' );
     286    if ( $currency ) {
     287      if ( $currency = self::CURRENCIES[ $currency ] ) $post[ 'CoinID' ] = $currency;
     288      else throw new Exception( 'CURRENCY_NOT_SUPPORTED_BY_ENGINE', 500 );
     289    }
     290
     291    $language = isset( $params[ 'language' ] ) ? $params[ 'language' ] : $this->param( 'language' );
     292    if ($language != '' ) $post[ 'Language' ] = $language;
    293293
    294294    if ( !isset( $params[ 'payments' ] ) || ( isset( $params[ 'payments' ] ) && $params[ 'payments' ] ) ) {
     
    302302    }
    303303
    304     $post['SuccessRedirectUrl'] = $this->url(SimplePayment::OPERATION_SUCCESS, $params);
    305     $post['ErrorRedirectUrl'] = $this->url(SimplePayment::OPERATION_ERROR, $params);
    306     $post['IndicatorUrl'] = $this->url(SimplePayment::OPERATION_STATUS, $params);
    307     $post['CancelUrl'] = $this->url(SimplePayment::OPERATION_CANCEL, $params);
    308     if ($this->param('css') != '') $post[ 'CSSUrl' ] = $this->callback.(strpos($this->callback, '?') !== false ? '&' : '?').'op=css';
    309 
    310     $post['CancelType'] = $this->cancelType;
    311 
    312     $creditType = $this->param('credit_type');
    313     if ($creditType != '') $post['CreditType'] = $creditType;
    314 
    315     $show = $this->param('show_invoice_operation');
    316     if ($operation != 3 && $show != '') $post['InvoiceHeadOperation'] = $operation == 3 ? 0 : $show;
    317 
    318     $show = $this->param('show_invoice_info');
    319     if ($operation != 3 && $show != '') $post['ShowInvoiceHead'] = $show;
    320 
    321     $docType = $this->param('doc_type');
    322     if ($operation != 3 && $docType != '') $post['DocTypeToCreate'] = $docType;
    323 
    324     $field = $this->param('field_name');
    325     if ($field != '') {
    326         $post['HideCardOwnerName'] = $field == 'hide' ? 'true' : 'false';
    327     }
    328 
    329     $field = $this->param('field_phone');
    330     if ($field != '') {
    331         $post['ReqCardOwnerPhone'] = $field == 'require' ? 'true' : 'false';
    332         $post['ShowCardOwnerPhone'] = $field == 'show' || $field == 'require' ? 'true' : 'false';
    333     }
    334 
    335     $field = $this->param('field_email');
    336     if ($field != '') {
    337         $post['ReqCardOwnerEmail'] = $field == 'require' ? 'true' : 'false';
    338         $post['ShowCardOwnerEmail'] = $field == 'show' || $field == 'require' ? 'true' : 'false';
     304    $post[ 'SuccessRedirectUrl' ] = $this->url( SimplePayment::OPERATION_SUCCESS, $params );
     305    $post[ 'ErrorRedirectUrl' ] = $this->url( SimplePayment::OPERATION_ERROR, $params );
     306    $post[ 'IndicatorUrl' ] = $this->url( SimplePayment::OPERATION_STATUS, $params );
     307    $post[ 'CancelUrl' ] = $this->url( SimplePayment::OPERATION_CANCEL, $params );
     308    if ( $this->param( 'css' ) != '' ) $post[ 'CSSUrl' ] = $this->callback . ( strpos( $this->callback, '?' ) !== false ? '&' : '?' ) . 'op=css';
     309
     310    $post[ 'CancelType' ] = $this->cancelType;
     311
     312    $creditType = $this->param( 'credit_type' );
     313    if ( $creditType != '' ) $post[ 'CreditType' ] = $creditType;
     314
     315    $show = $this->param( 'show_invoice_operation' );
     316    if ( $operation != 3 && $show != '' ) $post[ 'InvoiceHeadOperation' ] = $operation == 3 ? 0 : $show;
     317
     318    $show = $this->param( 'show_invoice_info' );
     319    if ( $operation != 3 && $show != '' ) $post[ 'ShowInvoiceHead' ] = $show;
     320
     321    $docType = $this->param( 'doc_type' );
     322    if ( $operation != 3 && $docType != '' ) $post[ 'DocTypeToCreate' ] = $docType;
     323
     324    $field = $this->param( 'field_name' );
     325    if ( $field != '' ) {
     326        $post[ 'HideCardOwnerName' ] = $field == 'hide' ? 'true' : 'false';
     327    }
     328
     329    $field = $this->param( 'field_phone' );
     330    if ( $field != '' ) {
     331        $post[ 'ReqCardOwnerPhone' ] = $field == 'require' ? 'true' : 'false';
     332        $post[ 'ShowCardOwnerPhone' ] = $field == 'show' || $field == 'require' ? 'true' : 'false';
     333    }
     334
     335    $field = $this->param( 'field_email' );
     336    if ( $field != '' ) {
     337        $post[ 'ReqCardOwnerEmail' ] = $field == 'require' ? 'true' : 'false';
     338        $post[ 'ShowCardOwnerEmail' ] = $field == 'show' || $field == 'require' ? 'true' : 'false';
    339339    }
    340340   
    341     if ((!isset($params['payments']) || $params['payments'] != "monthly") && $this->param('hide_user_id')) $post['HideCreditCardUserId'] = $this->param('hide_user_id') == 'true' ? 'true' : 'false';
    342 
    343     if ($operation != 3 && isset($params['company']) && $params['company']) $post['InvoiceHead.CustName'] = $params['company'];
    344     if ($operation != 3 && !isset($post['InvoiceHead.CustName']) && isset($params['full_name']) && $params['full_name']) $post['InvoiceHead.CustName'] = $params['full_name'];
    345     if ($operation != 3) $post = array_merge($post, $this->document(array_merge($params, ['language' => $language, 'currency' => $currency])));
     341    if ( ( !isset( $params[ 'payments' ]) || $params[ 'payments' ] != "monthly" ) && $this->param( 'hide_user_id' ) ) $post[ 'HideCreditCardUserId' ] = $this->param( 'hide_user_id' ) == 'true' ? 'true' : 'false';
     342
     343    if ( $operation != 3 && isset( $params[ 'company' ]) && $params[ 'company' ]) $post[ 'InvoiceHead.CustName' ] = $params[ 'company' ];
     344    if ( $operation != 3 && !isset( $post[ 'InvoiceHead.CustName' ]) && isset( $params[ 'full_name' ]) && $params[ 'full_name' ]) $post[ 'InvoiceHead.CustName' ] = $params[ 'full_name' ];
     345    if ( $operation != 3 ) $post = array_merge( $post, $this->document( array_merge( $params, [ 'language' => $language, 'currency' => $currency ] ) ));
    346346
    347347    // TODO: Analyze how to use those parameters
     
    365365    // SuspendedDealJValidateType
    366366    // SuspendedDealGroup
    367     $status = $this->post($this->api['payment_request'], $post);
    368     parse_str($status, $status);
    369     $status['url'] = $this->param('method') == 'paypal' ? $status['PayPalUrl'] : $status['url'];
    370     $this->transaction = $this->transaction ? : $status['LowProfileCode'];
     367    $status = $this->post( $this->api[ 'payment_request' ], $post );
     368    parse_str( $status, $status );
     369    $status[ 'url' ] = $this->param( 'method' ) == 'paypal' ? $status[ 'PayPalUrl' ] : $status[ 'url' ];
     370    $this->transaction = $this->transaction ? : $status[ 'LowProfileCode' ];
    371371    $response = $status;
    372     $this->save([
     372    $this->save( [
    373373      'transaction_id' => $this->transaction,
    374       'url' => $this->api['payment_request'],
    375       'status' => isset($response['ResponseCode']) ? $response['ResponseCode'] : $response['response_code'],
    376       'description' => isset($response['Description']) ? $response['Description'] : null,
    377       'request' => json_encode($post),
    378       'response' => json_encode($response)
    379     ]);
    380     if (isset($status['LowProfileCode']) && $status['LowProfileCode']) $this->transaction = $status['LowProfileCode'];
    381     if (isset($status['ResponseCode']) && $status['ResponseCode'] != 0) {
    382       throw new Exception($status['Description'], $status['ResponseCode']);
    383     }
    384     return($response);
     374      'url' => $this->api[ 'payment_request' ],
     375      'status' => isset( $response[ 'ResponseCode' ]) ? $response[ 'ResponseCode' ] : $response[ 'response_code' ],
     376      'description' => isset( $response[ 'Description' ]) ? $response[ 'Description' ] : null,
     377      'request' => json_encode( $post ),
     378      'response' => json_encode( $response )
     379    ] );
     380    if ( isset( $status[ 'LowProfileCode' ] ) && $status[ 'LowProfileCode' ] ) $this->transaction = $status[ 'LowProfileCode' ];
     381    if ( isset( $status[ 'ResponseCode' ] ) && $status[ 'ResponseCode' ] != 0 ) {
     382      throw new Exception( $status[ 'Description' ], $status[ 'ResponseCode' ] );
     383    }
     384    return( $response );
    385385  }
    386386
     
    389389   
    390390    if (!$this->sandbox) {
    391       $post['TerminalNumber'] = $this->param_part($params);
    392       $post['UserName'] = $this->param_part($params, 'username');
    393       $terminals = $this->param('terminal');
    394       $terminals = explode(';', $terminals);
     391      $post[ 'TerminalNumber' ] = $this->param_part($params);
     392      $post[ 'UserName' ] = $this->param_part($params, 'username' );
     393      $terminals = $this->param( 'terminal' );
     394      $terminals = explode( ';', $terminals);
    395395    } else {
    396       $post['TerminalNumber'] = $this->terminal;
    397       $post['UserName'] = $this->username;
    398     }
    399 
    400     if ($this->param('recurring_terminal')) $post['RecurringPayments.ChargeInTerminal'] = $this->param('recurring_terminal');
    401     $post['Operation'] = $this->param('reurring_operation');
    402     $post['LowProfileDealGuid'] = isset($params['lowprofilecode']) ? $params['lowprofilecode'] : $params['transaction_id'];
     396      $post[ 'TerminalNumber' ] = $this->terminal;
     397      $post[ 'UserName' ] = $this->username;
     398    }
     399
     400    if ($this->param( 'recurring_terminal' ) ) $post[ 'RecurringPayments.ChargeInTerminal' ] = $this->param( 'recurring_terminal' );
     401    $post[ 'Operation' ] = $this->param( 'reurring_operation' );
     402    $post[ 'LowProfileDealGuid' ] = isset($params[ 'lowprofilecode' ]) ? $params[ 'lowprofilecode' ] : $params[ 'transaction_id' ];
    403403   
    404     if ($this->param('department_id')) $post['RecurringPayments.DepartmentId'] = $this->param('department_id');
    405     //if (isset($params['payment_id']) && $params['payment_id']) $post['Account.SiteUniqueId'] = $params['payment_id'];
    406 
    407     if (isset($params['payment_id']) && $params['payment_id']) $post['RecurringPayments.ReturnValue'] = $params['payment_id'];
    408 
    409     $post['RecurringPayments.FlexItem.Price'] = $params['amount'];
    410     $post['RecurringPayments.FlexItem.InvoiceDescription'] = isset($params['product']) ? $params['product'] : $params['concept'];
    411     $post['RecurringPayments.InternalDecription'] = isset($params['product']) ? $params['product'] : $params['concept'];
     404    if ($this->param( 'department_id' ) ) $post[ 'RecurringPayments.DepartmentId' ] = $this->param( 'department_id' );
     405    //if (isset($params[ 'payment_id' ]) && $params[ 'payment_id' ]) $post[ 'Account.SiteUniqueId' ] = $params[ 'payment_id' ];
     406
     407    if (isset($params[ 'payment_id' ]) && $params[ 'payment_id' ]) $post[ 'RecurringPayments.ReturnValue' ] = $params[ 'payment_id' ];
     408
     409    $post[ 'RecurringPayments.FlexItem.Price' ] = $params[ 'amount' ];
     410    $post[ 'RecurringPayments.FlexItem.InvoiceDescription' ] = isset($params[ 'product' ]) ? $params[ 'product' ] : $params[ 'concept' ];
     411    $post[ 'RecurringPayments.InternalDecription' ] = isset($params[ 'product' ]) ? $params[ 'product' ] : $params[ 'concept' ];
    412412   
    413413    if (isset($params[SimplePayment::CARD_OWNER]) && $params[SimplePayment::CARD_OWNER]) {
    414       $post['Account.ContactName'] = $params[SimplePayment::CARD_OWNER];
    415     }
    416     if (!isset($post['CardOwnerName']) && isset($params['full_name']) && $params['full_name']) {
    417       $post['Account.ContactName'] = $params['full_name']; // card_holder
    418     }
    419 
    420     if (isset($params['first_name']) && $params['first_name']) $post['Account.FirstName'] = $params['first_name'];
    421     if (isset($params['last_name']) && $params['last_name']) $post['Account.FirstName'] = (isset($post['Account.FirstName']) && $post['Account.FirstName'] ? ' ' : '').$params['last_name'];
    422 
    423     if (isset($params['phone']) && $params['phone']) $post['Account.PhLine'] = $params['phone'];
    424     if (isset($params['mobile']) && $params['mobile']) $post['Account.PhMobile'] = $params['mobile'];
    425     if (isset($params['email']) && $params['email']) $post['Account.Email'] = $params['email'];
    426 
    427     if (isset($params['address']) && $params['address']) $post['Account.Street1'] = $params['address'];
    428     if (isset($params['address2']) && $params['address2']) $post['Account.Street2'] = $params['address2'];
    429     if (isset($params['zipcode']) && $params['zipcode']) $post['Account.ZipCode'] = $params['zipcode'];
    430     if (isset($params['city']) && $params['city']) $post['Account.City'] = $params['city'];
    431 
    432     if (isset($params['comment']) && $params['comment']) $post['Account.Comments'] = $params['comment'];
    433 
    434     if (isset($params['tax_id']) && $params['tax_id']) $post['Account.RegisteredBusinessNumber'] = $params['tax_id'];
    435 
    436     if ($this->param('vat_free')) $post['Account.VatFree'] = 'true';
    437 
    438     $language = isset($params['language']) ? $params['language'] : $this->param('language');
    439     if ($language != '') $post['Account.IsDocumentLangEnglish'] = $language == 'he' ? 'false' : 'true';
    440 
    441     $currency = isset($params['currency']) && $params['currency'] ? $params['currency'] : $this->param('currency');
    442     if ($currency != '') {
    443       if ($currency = self::CURRENCIES[$currency]) $post['RecurringPayments.FinalDebitCoinId'] = $currency;
    444       else throw new Exception('CURRENCY_NOT_SUPPORTED_BY_ENGINE', 500);
    445     }
    446 
    447     $post['codepage'] = 65001; // Codepage fixed to enable hebrew
     414      $post[ 'Account.ContactName' ] = $params[SimplePayment::CARD_OWNER];
     415    }
     416    if (!isset($post[ 'CardOwnerName' ]) && isset($params[ 'full_name' ]) && $params[ 'full_name' ]) {
     417      $post[ 'Account.ContactName' ] = $params[ 'full_name' ]; // card_holder
     418    }
     419
     420    if (isset($params[ 'first_name' ]) && $params[ 'first_name' ]) $post[ 'Account.FirstName' ] = $params[ 'first_name' ];
     421    if (isset($params[ 'last_name' ]) && $params[ 'last_name' ]) $post[ 'Account.FirstName' ] = (isset($post[ 'Account.FirstName' ]) && $post[ 'Account.FirstName' ] ? ' ' : '' ).$params[ 'last_name' ];
     422
     423    if (isset($params[ 'phone' ]) && $params[ 'phone' ]) $post[ 'Account.PhLine' ] = $params[ 'phone' ];
     424    if (isset($params[ 'mobile' ]) && $params[ 'mobile' ]) $post[ 'Account.PhMobile' ] = $params[ 'mobile' ];
     425    if (isset($params[ 'email' ]) && $params[ 'email' ]) $post[ 'Account.Email' ] = $params[ 'email' ];
     426
     427    if (isset($params[ 'address' ]) && $params[ 'address' ]) $post[ 'Account.Street1' ] = $params[ 'address' ];
     428    if (isset($params[ 'address2' ]) && $params[ 'address2' ]) $post[ 'Account.Street2' ] = $params[ 'address2' ];
     429    if (isset($params[ 'zipcode' ]) && $params[ 'zipcode' ]) $post[ 'Account.ZipCode' ] = $params[ 'zipcode' ];
     430    if (isset($params[ 'city' ]) && $params[ 'city' ]) $post[ 'Account.City' ] = $params[ 'city' ];
     431
     432    if (isset($params[ 'comment' ]) && $params[ 'comment' ]) $post[ 'Account.Comments' ] = $params[ 'comment' ];
     433
     434    if (isset($params[ 'tax_id' ]) && $params[ 'tax_id' ]) $post[ 'Account.RegisteredBusinessNumber' ] = $params[ 'tax_id' ];
     435
     436    if ($this->param( 'vat_free' ) ) $post[ 'Account.VatFree' ] = 'true';
     437
     438    $language = isset($params[ 'language' ]) ? $params[ 'language' ] : $this->param( 'language' );
     439    if ($language != '' ) $post[ 'Account.IsDocumentLangEnglish' ] = $language == 'he' ? 'false' : 'true';
     440
     441    $currency = isset($params[ 'currency' ]) && $params[ 'currency' ] ? $params[ 'currency' ] : $this->param( 'currency' );
     442    if ($currency != '' ) {
     443      if ($currency = self::CURRENCIES[$currency]) $post[ 'RecurringPayments.FinalDebitCoinId' ] = $currency;
     444      else throw new Exception( 'CURRENCY_NOT_SUPPORTED_BY_ENGINE', 500);
     445    }
     446
     447    $post[ 'codepage' ] = 65001; // Codepage fixed to enable hebrew
    448448    // month from now 28 days
    449449    $date = new DateTime();
    450     $date->add(new DateInterval('P28D')); // P1D means a period of 28 day
    451     $post['RecurringPayments.NextDateToBill'] = $date->format('d/m/Y');
     450    $date->add(new DateInterval( 'P28D' ) ); // P1D means a period of 28 day
     451    $post[ 'RecurringPayments.NextDateToBill' ] = $date->format( 'd/m/Y' );
    452452
    453453    $limit = $this->param( 'recurring_total' );
    454     $post['RecurringPayments.TotalNumOfBills'] = $limit ? : 999999;
    455 
    456     $interval = $this->param('recurring_interval');
    457     if ($interval) $post['TimeIntervalId'] = $interval;
     454    $post[ 'RecurringPayments.TotalNumOfBills' ] = $limit ? : 999999;
     455
     456    $interval = $this->param( 'recurring_interval' );
     457    if ($interval) $post[ 'TimeIntervalId' ] = $interval;
    458458 
    459     $docType = $this->param('doc_type');
    460     if ($docType != '') $post['RecurringPayments.DocTypeToCreate'] = $docType;
    461 
    462     $post['RecurringPayments.FlexItem.IsPriceIncludeVat'] = 'true'; // Must be true - API requirement
     459    $docType = $this->param( 'doc_type' );
     460    if ($docType != '' ) $post[ 'RecurringPayments.DocTypeToCreate' ] = $docType;
     461
     462    $post[ 'RecurringPayments.FlexItem.IsPriceIncludeVat' ] = 'true'; // Must be true - API requirement
    463463    // TODO: assure to verifiy first_name / lasstname or use full name
    464     if (isset($params['full_name']) && trim($params['full_name'])) $post['Account.CompanyName'] = trim($params['full_name']);
    465     if (!isset($post['Account.CompanyName']) && isset($params['first_name']) && trim($params['first_name'])) $post['Account.CompanyName'] = trim($params['first_name'].(isset($params['last_name']) ? ' '.$params['last_name'] : ''));
    466     if (!isset($post['Account.CompanyName']) && isset($params['last_name']) && trim($params['last_name'])) $post['Account.CompanyName'] = trim($params['last_name']);
    467     if (isset($params['company']) && trim($params['company'])) $post['Account.CompanyName'] = trim($params['company']);
     464    if (isset($params[ 'full_name' ]) && trim($params[ 'full_name' ]) ) $post[ 'Account.CompanyName' ] = trim($params[ 'full_name' ]);
     465    if (!isset($post[ 'Account.CompanyName' ]) && isset($params[ 'first_name' ]) && trim($params[ 'first_name' ]) ) $post[ 'Account.CompanyName' ] = trim($params[ 'first_name' ].(isset($params[ 'last_name' ]) ? ' '.$params[ 'last_name' ] : '' ) );
     466    if (!isset($post[ 'Account.CompanyName' ]) && isset($params[ 'last_name' ]) && trim($params[ 'last_name' ]) ) $post[ 'Account.CompanyName' ] = trim($params[ 'last_name' ]);
     467    if (isset($params[ 'company' ]) && trim($params[ 'company' ]) ) $post[ 'Account.CompanyName' ] = trim($params[ 'company' ]);
    468468    // Not in use:
    469469    //  Account.AccountId   ,
     
    471471    // Account.ForeignAccountNumber , RecurringPayments.IsActive   
    472472    // BankInfo.Bank     BankInfo.Branch    BankInfo.AccountNumber   BankInfo.Description   
    473     $status = $this->post($this->api['recurring_request'], $post);
     473    $status = $this->post($this->api[ 'recurring_request' ], $post);
    474474    parse_str($status, $status);
    475475    $response = $status;
    476476    $this->save([
    477477      'transaction_id' => $this->transaction,
    478       'url' => $this->api['recurring_request'],
    479       'status' => isset($response['ResponseCode']) ? $response['ResponseCode'] : $response['response_code'],
    480       'description' => isset($response['Description']) ? $response['Description'] : null,
     478      'url' => $this->api[ 'recurring_request' ],
     479      'status' => isset($response[ 'ResponseCode' ]) ? $response[ 'ResponseCode' ] : $response[ 'response_code' ],
     480      'description' => isset($response[ 'Description' ]) ? $response[ 'Description' ] : null,
    481481      'request' => json_encode($post),
    482482      'response' => json_encode($response)
     
    499499  public function recur( $params ) {
    500500    $this->transaction = self::uuid();
    501     //$this->transaction = $params['transaction_id'];
     501    //$this->transaction = $params[ 'transaction_id' ];
    502502    $this->confirmation_code = $this->charge( $params );
    503503    return( $this->confirmation_code );
     
    509509      $post[ 'terminalnumber' ] = $this->param_part( $params );
    510510      $post[ 'username' ] = $this->param_part( $params, 'username' );
    511      // $post['TokenToCharge.UserPassword'] = $this->param_part($params, 'password');
     511     // $post[ 'TokenToCharge.UserPassword' ] = $this->param_part($params, 'password' );
    512512    } else {
    513513      $post[ 'terminalnumber' ] = $this->terminal;
     
    515515    }
    516516
    517     if ($refund) $post['TokenToCharge.UserPassword'] = $this->password;
    518 
    519     $token = $params['token'] ? json_decode($params['token'], true) : null;
     517    if ($refund) $post[ 'TokenToCharge.UserPassword' ] = $this->password;
     518
     519    $token = $params[ 'token' ] ? json_decode($params[ 'token' ], true) : null;
    520520    if ($token) {
    521       $post['TokenToCharge.Token'] = $token['token'];//$this->transaction;
    522       if (isset($token[SimplePayment::CARD_EXPIRY_YEAR])) $post['TokenToCharge.CardValidityYear'] = $token[SimplePayment::CARD_EXPIRY_YEAR];
    523       if (isset($token[SimplePayment::CARD_EXPIRY_MONTH])) $post['TokenToCharge.CardValidityMonth'] = $token[SimplePayment::CARD_EXPIRY_MONTH];     
    524       if (isset($token[SimplePayment::CARD_OWNER_ID])) $post['TokenToCharge.IdentityNumber'] = $token[SimplePayment::CARD_OWNER_ID];
    525     }
    526     $post['TokenToCharge.SumToBill'] = $params['amount'];
    527 
    528     $currency = isset($params[SimplePayment::CURRENCY]) && $params[SimplePayment::CURRENCY] ? $params[SimplePayment::CURRENCY] : $this->param('currency');
    529     if ($currency != '') {
    530       if ($currency = self::CURRENCIES[$currency]) $post['CoinID'] = $currency;
    531       else throw new Exception('CURRENCY_NOT_SUPPORTED_BY_ENGINE', 500);
    532     }
    533 
    534     $post['TokenToCharge.CoinID'] = $currency;
    535 
    536 
    537 
    538 
    539     $language = $this->param('language');
    540     if ($language != '') $post['Language'] = $language;
     521      $post[ 'TokenToCharge.Token' ] = $token[ 'token' ];//$this->transaction;
     522      if (isset($token[SimplePayment::CARD_EXPIRY_YEAR]) ) $post[ 'TokenToCharge.CardValidityYear' ] = $token[SimplePayment::CARD_EXPIRY_YEAR];
     523      if (isset($token[SimplePayment::CARD_EXPIRY_MONTH]) ) $post[ 'TokenToCharge.CardValidityMonth' ] = $token[SimplePayment::CARD_EXPIRY_MONTH];     
     524      if (isset($token[SimplePayment::CARD_OWNER_ID]) ) $post[ 'TokenToCharge.IdentityNumber' ] = $token[SimplePayment::CARD_OWNER_ID];
     525    }
     526    $post[ 'TokenToCharge.SumToBill' ] = $params[ 'amount' ];
     527
     528    $currency = isset($params[SimplePayment::CURRENCY]) && $params[SimplePayment::CURRENCY] ? $params[SimplePayment::CURRENCY] : $this->param( 'currency' );
     529    if ($currency != '' ) {
     530      if ($currency = self::CURRENCIES[$currency]) $post[ 'CoinID' ] = $currency;
     531      else throw new Exception( 'CURRENCY_NOT_SUPPORTED_BY_ENGINE', 500);
     532    }
     533
     534    $post[ 'TokenToCharge.CoinID' ] = $currency;
     535
     536
     537
     538
     539    $language = $this->param( 'language' );
     540    if ($language != '' ) $post[ 'Language' ] = $language;
    541541
    542542    //  TokenToCharge.CardOwnerName
     
    547547
    548548
    549     if ($refund) $post['TokenToCharge.RefundInsteadOfCharge'] = $refund;
    550     if ($params['PAYMENTS'] == 'monthly') $post['TokenToCharge.IsAutoRecurringPayment'] = 'true';
    551 
    552     if (isset($params['approval_number']) && $params['approval_number']) $post['TokenToCharge.ApprovalNumber'] = $params['approval_number'];
    553 
    554 
    555     // $post = array_merge($post, $this->document(array_merge($params, ['language' => $language, 'currency' => $currency])));
    556 
    557     $status = $this->post($this->api['payment_recur'], $post);
     549    if ($refund) $post[ 'TokenToCharge.RefundInsteadOfCharge' ] = $refund;
     550    if ($params[ 'PAYMENTS' ] == 'monthly' ) $post[ 'TokenToCharge.IsAutoRecurringPayment' ] = 'true';
     551
     552    if (isset($params[ 'approval_number' ]) && $params[ 'approval_number' ]) $post[ 'TokenToCharge.ApprovalNumber' ] = $params[ 'approval_number' ];
     553
     554
     555    // $post = array_merge($post, $this->document(array_merge($params, [ 'language' => $language, 'currency' => $currency]) ));
     556
     557    $status = $this->post($this->api[ 'payment_recur' ], $post);
    558558    parse_str($status, $status);
    559559    $response = $status;
    560560    $this->save([
    561561      'transaction_id' => $this->transaction,
    562       'url' => $this->api['payment_recur'],
    563       'status' => isset($response['ResponseCode']) ? $response['ResponseCode'] : $response['response_code'],
    564       'description' => isset($response['Description']) ? $response['Description'] : null,
     562      'url' => $this->api[ 'payment_recur' ],
     563      'status' => isset($response[ 'ResponseCode' ]) ? $response[ 'ResponseCode' ] : $response[ 'response_code' ],
     564      'description' => isset($response[ 'Description' ]) ? $response[ 'Description' ] : null,
    565565      'request' => json_encode($post),
    566566      'response' => json_encode($response),
     
    568568    ]);
    569569    // InternalDealNumber
    570     return($response['ResponseCode'] == 0 ? $response['InternalDealNumber'] : false);
     570    return($response[ 'ResponseCode' ] == 0 ? $response[ 'InternalDealNumber' ] : false);
    571571    // Not in use:
    572572    // TokenToCharge.Salt, TokenToCharge.SumInStars, TokenToCharge.NumOfPayments
     
    581581  protected function document($params) {
    582582    $post = [];
    583     $language = $this->param('language');
    584     $currency = isset($params[SimplePayment::CURRENCY]) ? $params[SimplePayment::CURRENCY] : $this->param('currency');
    585     if ($language) $post['InvoiceHead.Languge'] = $params['language'];
    586     if ($currency) $post['InvoiceHead.CoinID'] = $params['currency'];
    587 
    588     if (isset($params['email']) && $params['email']) $post['InvoiceHead.Email'] = $params['email'];
     583    $language = $this->param( 'language' );
     584    $currency = isset($params[SimplePayment::CURRENCY]) ? $params[SimplePayment::CURRENCY] : $this->param( 'currency' );
     585    if ($language) $post[ 'InvoiceHead.Languge' ] = $params[ 'language' ];
     586    if ($currency) $post[ 'InvoiceHead.CoinID' ] = $params[ 'currency' ];
     587
     588    if (isset($params[ 'email' ]) && $params[ 'email' ]) $post[ 'InvoiceHead.Email' ] = $params[ 'email' ];
    589589   
    590     if (!$this->param('doc_details') || in_array($this->param('doc_details'), ['address', 'full'])) {
    591       if (isset($params['address']) && $params['address']) $post['InvoiceHead.CustAddresLine1'] = $params['address'];
    592       if (isset($params['address2']) && $params['address2']) $post['InvoiceHead.CustAddresLine2'] = $params['address2'];
    593       if (isset($params['city']) && $params['city']) $post['InvoiceHead.CustCity'] = $params['city'];
    594     }
    595     if (!$this->param('doc_details') || in_array($this->param('doc_details'), ['contact', 'full'])) {
    596       if (isset($params['phone']) && $params['phone']) $post['InvoiceHead.CustLinePH'] = $params['phone'];
    597       if (isset($params['mobile']) && $params['mobile']) $post['InvoiceHead.CustMobilePH'] = $params['mobile'];
    598     }
    599 
    600     if (isset($params['tax_id']) && $params['tax_id']) $post['InvoiceHead.CompID'] = $params['tax_id'];
    601     if (isset($params['comment']) && $params['comment']) $post['InvoiceHead.Comments'] = $params['comment'];
    602     if ($this->param('email_invoice')) $post['InvoiceHead.SendByEmail'] = 'true';
    603     if ($this->param('vat_free')) $post['InvoiceHead.ExtIsVatFree'] = 'true';
    604     if ($this->param('auto_create_account')) $post['InvoiceHead.IsAutoCreateUpdateAccount'] = 'true';
    605     if ($this->param('auto_load_account')) $post['InvoiceHead.IsLoadInfoFromAccountID'] = 'true';
    606     if ($this->param('department_id')) $post['InvoiceHead.DepartmentId'] = $this->param('department_id');
    607     //if ( isset($params['payment_id']) && $params['payment_id']) $post['InvoiceHead.SiteUniqueId'] = $params['payment_id'];
     590    if (!$this->param( 'doc_details' ) || in_array($this->param( 'doc_details' ), [ 'address', 'full' ]) ) {
     591      if (isset($params[ 'address' ]) && $params[ 'address' ]) $post[ 'InvoiceHead.CustAddresLine1' ] = $params[ 'address' ];
     592      if (isset($params[ 'address2' ]) && $params[ 'address2' ]) $post[ 'InvoiceHead.CustAddresLine2' ] = $params[ 'address2' ];
     593      if (isset($params[ 'city' ]) && $params[ 'city' ]) $post[ 'InvoiceHead.CustCity' ] = $params[ 'city' ];
     594    }
     595    if (!$this->param( 'doc_details' ) || in_array($this->param( 'doc_details' ), [ 'contact', 'full' ]) ) {
     596      if (isset($params[ 'phone' ]) && $params[ 'phone' ]) $post[ 'InvoiceHead.CustLinePH' ] = $params[ 'phone' ];
     597      if (isset($params[ 'mobile' ]) && $params[ 'mobile' ]) $post[ 'InvoiceHead.CustMobilePH' ] = $params[ 'mobile' ];
     598    }
     599
     600    if (isset($params[ 'tax_id' ]) && $params[ 'tax_id' ]) $post[ 'InvoiceHead.CompID' ] = $params[ 'tax_id' ];
     601    if (isset($params[ 'comment' ]) && $params[ 'comment' ]) $post[ 'InvoiceHead.Comments' ] = $params[ 'comment' ];
     602    if ($this->param( 'email_invoice' ) ) $post[ 'InvoiceHead.SendByEmail' ] = 'true';
     603    if ($this->param( 'vat_free' ) ) $post[ 'InvoiceHead.ExtIsVatFree' ] = 'true';
     604    if ($this->param( 'auto_create_account' ) ) $post[ 'InvoiceHead.IsAutoCreateUpdateAccount' ] = 'true';
     605    if ($this->param( 'auto_load_account' ) ) $post[ 'InvoiceHead.IsLoadInfoFromAccountID' ] = 'true';
     606    if ($this->param( 'department_id' ) ) $post[ 'InvoiceHead.DepartmentId' ] = $this->param( 'department_id' );
     607    //if ( isset($params[ 'payment_id' ]) && $params[ 'payment_id' ]) $post[ 'InvoiceHead.SiteUniqueId' ] = $params[ 'payment_id' ];
    608608
    609609    if ( isset( $params[ 'products' ] ) && is_array( $params[ 'products' ] ) ) {
     
    615615        $post[ 'InvoiceLines' . $index . '.Quantity' ] = $product[ 'qty' ];
    616616        $post[ 'InvoiceLines' . $index . '.IsPriceIncludeVAT' ] = 'true'; // Must be true - API requirement
    617         // TODO: support per item: $post['InvoiceLines1.IsVatFree'] = 'true';
     617        // TODO: support per item: $post[ 'InvoiceLines1.IsVatFree' ] = 'true';
    618618        if ( isset( $product[ 'id' ] ) && $product[ 'id' ] ) $post[ 'InvoiceLines' . $index . '.ProductID' ] = $product[ 'id' ];
    619619        $index++;
    620620      }
    621621    } else {
    622       $post[ 'InvoiceLines1.Description'] = $params['product'];
    623       $post[ 'InvoiceLines1.Price'] = $params['amount'];
    624       $post[ 'InvoiceLines1.Quantity'] = 1;
    625       $post[ 'InvoiceLines1.IsPriceIncludeVAT'] = 'true'; // Must be true - API requirement
    626       // TODO: support per item: $post['InvoiceLines1.IsVatFree'] = 'true';
     622      $post[ 'InvoiceLines1.Description' ] = $params[ 'product' ];
     623      $post[ 'InvoiceLines1.Price' ] = $params[ 'amount' ];
     624      $post[ 'InvoiceLines1.Quantity' ] = 1;
     625      $post[ 'InvoiceLines1.IsPriceIncludeVAT' ] = 'true'; // Must be true - API requirement
     626      // TODO: support per item: $post[ 'InvoiceLines1.IsVatFree' ] = 'true';
    627627      if ( isset( $params[ 'id' ] ) && $params[ 'id' ] ) $post[ 'InvoiceLines1.ProductID' ] = $params[ 'id' ];
    628628    }
     
    652652    return($post);
    653653  }
     654
     655//https://asmachta.co.il/?engine=Cardcom&payment_id=127046&redirect_url=https%3A%2F%2Fasmachta.co.il%2F%25d7%25a0%25d7%25a1%25d7%2597-%25d7%2598%25d7%2590%25d7%2591%25d7%2595%2F%3Fgf_simplepayment_return%3DaWRzPTJ8MTM0Nzk0Jmhhc2g9YWRkYmFjYmZiZGRjNDdlMTlkY2E1NzBiYjA0NmZkNzk&terminalnumber=125527&lowprofilecode=83fccd5d-6aed-4235-a1ab-62aceb769fad&ResponeCode=0&Operation=1&ResponseCode=0&Status=0
     656  // Sanitize url for Cardcom, so we wont send cardcom parameters
     657  public function url( $type, $params = null ) {
     658    if ( $url = parent::url( $type, $params ) ) {
     659      $parts = parse_url( $url );
     660      if ( isset( $parts[ 'query' ] ) ) {
     661        parse_str( $parts[ 'query' ], $query );
     662        foreach ( [ 'terminalnumber', 'lowprofilecode', 'ResponeCode', 'Operation', 'ResponseCode', 'Status', 'DealRespone', 'InvoiceResponseCode', 'OperationResponse', 'OperationResponseText', 'ReturnValue' ] as $param ) {
     663          unset( $query[ $param ] );
     664        }
     665        $parts[ 'query' ] = http_build_query( $query );
     666        $url = $parts[ 'scheme' ] . '://' . $parts[ 'host' ];
     667        if ( isset( $parts[ 'port' ]) ) {
     668          $url .= ':' . $parts[ 'port' ];
     669        }
     670        if ( isset( $parts[ 'path' ] ) ) {
     671          $url .= $parts[ 'path' ];
     672        }
     673        if ( $parts[ 'query' ] ) {
     674          $url .= '?' . $parts[ 'query' ];
     675        }
     676        if ( isset( $parts[ 'fragment' ] ) ) {
     677          $url .= '#' . $parts[ 'fragment' ];
     678        }
     679      }
     680    }
     681    return( $url );
     682  }
    654683 
    655684}
  • simple-payment/tags/2.4.1/vendor/yalla-ya/simple-payment/Engines/Engine.php

    r3318371 r3319619  
    137137    public function url( $type, $params = null ) {
    138138      $url = $this->callback;
    139       $qry = [];
     139      $qry = [
     140        'op' => $type,
     141        'engine' => static::$name
     142      ];
    140143      if ( strpos( $url, 'transaction_id' ) === false ) $qry[ 'transaction_id' ] = $this->transaction;
    141144      if ( isset( $params[ 'payments' ] ) && strpos( $url, 'payments' ) === false ) $qry[ 'payments' ] = $params[ 'payments' ];
     
    143146      if ( isset( $params[ 'target' ] ) && strpos( $url, 'target' ) === false ) $qry[ 'target' ] = $params[ 'target' ];
    144147      if ( isset( $params[ 'redirect_url' ] ) && strpos( $url, 'redirect_url' ) === false ) $qry[ 'redirect_url' ] = $params[ 'redirect_url' ];
    145       return( $url . ( strpos( $url, '?' ) ? '&' : '?' ) . 'op=' . $type . '&engine=' . static::$name . ( $qry ? '&' . http_build_query( $qry ) : '' ) );
     148      return( $url . ( strpos( $url, '?' ) ? '&' : '?' ) . ( $qry ? '&' . http_build_query( $qry ) : '' ) );
    146149    }
    147150
  • simple-payment/trunk/addons/gravityforms/init.php

    r3318371 r3319619  
    573573
    574574    public function return_url( $form_id, $lead_id ) {
    575         // Lets use wordpress built-in function site_url
    576         /*$pageURL = GFCommon::is_ssl() ? 'https://' : 'http://';
    577         $server_port = apply_filters( 'gform_simplepayment_return_url_port', $_SERVER['SERVER_PORT'] );
    578         if ( $server_port != '80' && $server_port != 443) {
    579             $pageURL .= $_SERVER['SERVER_NAME'] . ':' . $server_port . $_SERVER['REQUEST_URI'];
    580         } else {
    581             $pageURL .= $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    582         }*/
    583575        $pageURL = site_url( $_SERVER[ 'REQUEST_URI' ] );
    584576        $ids_query = "ids={$form_id}|{$lead_id}";
     
    793785         * @param array $entry           The entry object currently being processed.
    794786         */
    795         $params[ 'redirect_url' ] = get_bloginfo( 'url' ) . '/?page=gf_simplepayment_ipn&entry_id=' . $entry[ 'id' ] . '&redirect_url=' . urlencode($this->return_url( $form[ 'id' ], $entry[ 'id' ] ) ) . ( isset( $params[ 'target' ] ) && $params[ 'target' ] ? '&target=' . $params[ 'target' ] : '' );
     787        $params[ 'redirect_url' ] = get_bloginfo( 'url' ) . '/?page=gf_simplepayment_ipn&entry_id=' . $entry[ 'id' ] . '&redirect_url=' . urlencode( $this->return_url( $form[ 'id' ], $entry[ 'id' ] ) ) . ( isset( $params[ 'target' ] ) && $params[ 'target' ] ? '&target=' . $params[ 'target' ] : '' );
    796788        $this->add_sp_pre_process( $feed, $submission_data, $form, $entry );
    797789        $params = apply_filters( 'gform_simplepayment_args_before_payment', $params, $form[ 'id' ], $submission_data, $feed, $entry );
  • simple-payment/trunk/admin/admin.php

    r3318371 r3319619  
    5656            }
    5757        }
    58         add_action( 'admin_menu', [ $this, 'add_plugin_options_page' ] );
     58        //add_action( 'admin_menu', [ $this, 'add_plugin_options_page' ] );
    5959        if ( !empty( $GLOBALS[ 'pagenow' ] ) ) {
    6060            switch ( $GLOBALS[ 'pagenow' ] ) {
     
    6868            }
    6969        }
     70
     71        $_active_plugins = array_merge( is_multisite() ? array_keys( get_site_option( 'active_sitewide_plugins', [] ) ) : [], get_option( 'active_plugins', [] ) );
     72        //if ( in_array( 'admin-columns-pro/admin-columns-pro.php', $_active_plugins ) ) {
     73        //  add_action( 'after_setup_theme', function () {
     74        //      require_once( SPWP_PLUGIN_DIR . '/addons/admin-columns-pro/init.php' );
     75        //  } );
     76        //}
     77
     78        add_action( 'admin_enqueue_scripts', function () {
     79            wp_enqueue_script( 'simple-payment-admin-js', plugin_dir_url( __FILE__ ) . 'script.js', [], false, true );
     80            wp_enqueue_style( 'simple-payment-admin-css', plugin_dir_url( __FILE__ ) . 'style.css', [], false );
     81        } );
     82
     83        add_action( 'admin_init', [ $this, 'register_license_settings' ] );
     84        //add_action( 'sp_admin_tabs', [ $this, 'add_plugin_settings' ] );
     85        //add_filter( 'sp_admin_sections', [ $this, 'add_plugin_settings' ] );
    7086    }
    7187
     
    177193          'simple-payments',
    178194          [ $this, 'render_transactions' ],
    179           plugin_dir_url( __FILE__ ) . 'assets/simple-payment-icon.png',
     195          SPWP_PLUGIN_URL . 'assets/simple-payment-icon.png',
    180196          30
    181197      );
     
    463479        ] );
    464480        require( SPWP_PLUGIN_DIR.'/admin/transaction-list-table.php' );
    465         $list = new Transaction_List();
     481        $list =  new Transaction_List(); // Consider using different List when using ACP - did_action( 'acp/ready' );
    466482    }
    467483
  • simple-payment/trunk/admin/style.css

    r2176343 r3319619  
    11.ttablenav .alignleft:nth-of-type(2n) { clear: both; }
    2 pre.json {}
    32pre.json .string { color: green; }
    43pre.json .number { color: darkorange; }
     
    76pre.json .key { color: red; }
    87pre.url { word-break: break-all; white-space: pre-wrap; }
     8.transaction-overview {
     9    display: flex;
     10    flex-wrap: wrap;
     11    row-gap: 5px;
     12    column-gap: 5px;
     13    justify-content: space-between;
     14}
     15.transaction-item {
     16    padding: 5px;
     17    display: flex;
     18    justify-content: space-between;
     19    flex-grow: 1;
     20    order: 0;
     21    row-gap: 5px;
     22    column-gap: 5px;
     23}
     24
     25.transaction-item.item-parameters {
     26    order: 100;
     27}
     28
     29.transaction-item.item-redirect_url, .transaction-item.item-parameters, .transaction-item.item-user_agent {
     30    flex-basis: 100%;
     31    flex-direction: column;
     32}
  • simple-payment/trunk/admin/transaction-list-table.php

    r3318406 r3319619  
    352352    } else {
    353353      $screen = get_current_screen();
     354      //print_r(  $screen );
    354355      $per_page = get_user_meta(get_current_user_id(), $screen->get_option('per_page', 'option'), true);
    355356      $per_page = $per_page ? $per_page : $this->get_items_per_page( 'per_page', $screen->get_option('per_page', 'default'));
  • simple-payment/trunk/admin/transaction-log.php

    r2448085 r3319619  
    1313    ?>
    1414    <hr class="wp-header-end">
     15    <div class="transaction-overview">
     16    <?php
     17    $payment = SimplePaymentPlugin::instance()->fetch( $_REQUEST[ 'id' ] );
     18    foreach( $payment as $key => $value ) {
     19        if ( ! empty( $value ) ) {
     20            echo '<div class="transaction-item item-' . $key . '"><strong>' . esc_html( ucfirst( $key ) ) . ':</strong> ' . ( !is_array( $value ) ? esc_html( $value ) : '<pre class="json">' . json_encode( $value ) . '</pre>' ) . '</div>';
     21        }
     22    }
     23    ?>
     24    </div>
    1525    <?php $list->views(); ?>
    1626    <form id="transaction-logs-filter" method="get">
  • simple-payment/trunk/engines/cardcom.php

    r3318371 r3319619  
    1616}, 1000, 2 );
    1717
     18/*
    1819add_filter( 'sp_payment_callback', function( $url ) {
    1920    global $SPWP;
    20     if ( !$SPWP::param( 'cardcom.short_urls' ) ) return;
     21    if ( !$SPWP::param( 'cardcom.short_urls' ) ) return( $url );
    2122    $uid = wp_generate_uuid4();
    2223    set_transient( 'sp_' . $uid, $url ); // TODO: should we define expiration/ 5 days?
    23     $url = add_query_arg( [
    24         $SPWP::OP => $SPWP::OPERATION_REDIRECT,
    25         '_spr' => $uid
    26     ], site_url() );
     24    //$url = add_query_arg( [
     25    //  $SPWP::SPRD => $SPWP::OPERATION_REDIRECT,
     26    //  '_spr' => $uid
     27    //], site_url() );
    2728    return( $url );
    2829}, 5000  );
     30*/
     31
     32add_filter( 'gform_simplepayment_return_url', function( $url, $form_id, $lead_id ) {
     33    global $SPWP;
     34    if ( !$SPWP::param( 'cardcom.short_urls' ) ) return( $url );
     35    $pageURL = site_url( '/_gf-sp' );
     36    $ids_query = "ids={$form_id}|{$lead_id}";
     37    $ids_query .= '&hash=' . wp_hash( $ids_query );
     38    $url = remove_query_arg( 'gf_simplepayment_retry', $pageURL );
     39    $url = add_query_arg( 'gf_simplepayment_return', base64_encode( $ids_query ), $url );
     40    return( $url );
     41}, 50, 3 );
     42
    2943
    3044add_filter( 'sp_payment_callback', function( $callback ) {
  • simple-payment/trunk/languages/simple-payment.pot

    r3318406 r3319619  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Simple Payment 2.3.9\n"
     5"Project-Id-Version: Simple Payment 2.4.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/simple-payment\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2025-06-26T17:29:54+00:00\n"
     12"POT-Creation-Date: 2025-06-30T00:08:12+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1414"X-Generator: WP-CLI 2.10.0\n"
     
    1717#. Plugin Name of the plugin
    1818#: simple-payment-plugin.php
     19#: addons/admin-columns-pro/classes/Service/ColumnGroup.php:20
     20#: addons/admin-columns-pro/classes/Service/ListScreens.php:19
    1921#: addons/elementor/widget.php:31
    2022#: addons/woocommerce/init.php:127
    2123#: addons/woocommerce/init.php:248
    2224#: addons/wpjobboard/config.php:8
    23 #: admin/admin.php:166
    24 #: admin/admin.php:167
     25#: admin/admin.php:182
     26#: admin/admin.php:183
    2527msgid "Simple Payment"
    2628msgstr ""
     
    445447msgstr ""
    446448
    447 #: addons/gravityforms/init.php:987
     449#: addons/gravityforms/init.php:979
    448450msgid "Payment Completed"
    449451msgstr ""
    450452
    451 #: addons/gravityforms/init.php:988
     453#: addons/gravityforms/init.php:980
    452454msgid "Payment Failed"
    453455msgstr ""
    454456
    455 #: addons/gravityforms/init.php:989
     457#: addons/gravityforms/init.php:981
    456458msgid "Subscription Created"
    457459msgstr ""
    458460
    459 #: addons/gravityforms/init.php:1389
     461#: addons/gravityforms/init.php:1381
    460462#: addons/woocommerce/init.php:206
    461463#: templates/form-woocommerce.php:65
     
    682684msgstr ""
    683685
    684 #: admin/admin.php:86
     686#: admin/admin.php:102
    685687msgid "Thanks for updating Simple Payment, you can checkout for new features and updates <a href=\"https://simple-payment.yalla-ya.com\" target=\"_blank\">here</a>."
    686688msgstr ""
    687689
    688 #: admin/admin.php:90
     690#: admin/admin.php:106
    689691msgid "Thanks for installing Simple Payment, after your test our plugin, dont forget to get your license to process real transactions, you can do it <a href=\"https://simple-payment.yalla-ya.com\" target=\"_blank\">here</a>."
    690692msgstr ""
    691693
    692 #: admin/admin.php:116
     694#: admin/admin.php:132
    693695msgid "View Simple Payment documentation"
    694696msgstr ""
    695697
    696 #: admin/admin.php:116
     698#: admin/admin.php:132
    697699msgid "Docs"
    698700msgstr ""
    699701
    700 #: admin/admin.php:117
     702#: admin/admin.php:133
    701703msgid "Visit premium customer support"
    702704msgstr ""
    703705
    704 #: admin/admin.php:117
     706#: admin/admin.php:133
    705707msgid "Premium support"
    706708msgstr ""
    707709
    708 #: admin/admin.php:159
    709 #: admin/admin.php:356
     710#: admin/admin.php:175
     711#: admin/admin.php:372
    710712#: admin/settings.php:123
    711713#: settings.php:122
     
    713715msgstr ""
    714716
    715 #: admin/admin.php:174
    716 #: admin/admin.php:175
     717#: admin/admin.php:190
     718#: admin/admin.php:191
    717719#: admin/transaction-list-table.php:241
    718720msgid "Payments"
    719721msgstr ""
    720722
    721 #: admin/admin.php:185
    722 #: admin/admin.php:186
     723#: admin/admin.php:201
     724#: admin/admin.php:202
    723725msgid "Transaction Details"
    724726msgstr ""
    725727
    726 #: admin/admin.php:207
     728#: admin/admin.php:223
    727729msgid "Simple Payment Settings"
    728730msgstr ""
    729731
    730 #: admin/admin.php:243
     732#: admin/admin.php:259
    731733msgid "License Key"
    732734msgstr ""
    733735
    734 #: admin/admin.php:406
     736#: admin/admin.php:422
    735737msgid "Auto"
    736738msgstr ""
    737739
    738 #: admin/admin.php:541
     740#: admin/admin.php:557
    739741msgid "License key is required"
    740742msgstr ""
    741743
    742 #: admin/admin.php:566
     744#: admin/admin.php:582
    743745msgid "License is not valid on the current domain"
    744746msgstr ""
    745747
    746 #: admin/admin.php:574
     748#: admin/admin.php:590
    747749msgid "License has not been activated"
    748750msgstr ""
    749751
    750 #: admin/admin.php:579
     752#: admin/admin.php:595
    751753msgid "License key was not found"
    752754msgstr ""
    753755
    754 #: admin/admin.php:583
     756#: admin/admin.php:599
    755757msgid "Unhandled error:"
    756758msgstr ""
     
    19631965msgstr ""
    19641966
    1965 #: simple-payment-plugin.php:142
     1967#: simple-payment-plugin.php:144
    19661968msgid "Simple Payment License Error: %s"
    19671969msgstr ""
    19681970
    1969 #: simple-payment-plugin.php:142
     1971#: simple-payment-plugin.php:144
    19701972msgid "License error, or no license."
    19711973msgstr ""
    19721974
    1973 #: simple-payment-plugin.php:188
     1975#: simple-payment-plugin.php:190
    19741976msgid "Every %s Minutes"
    19751977msgstr ""
    19761978
    1977 #: simple-payment-plugin.php:584
     1979#: simple-payment-plugin.php:587
    19781980msgid "Error payment recharge"
    19791981msgstr ""
    19801982
    1981 #: simple-payment-plugin.php:833
     1983#: simple-payment-plugin.php:836
    19821984msgid "Couldn't update transaction: %s"
    19831985msgstr ""
  • simple-payment/trunk/readme.txt

    r3318406 r3319619  
    44Tags: credit card, simple payment, donation, membership, checkout, payment request, payment gateway, sales, woocommerce, store, ecommerce, e-commerce, commerce, gutenberg, elementor, cardcom, icount, icredit, payme, isracard, paypal
    55Requires at least: 4.6
    6 Tested up to: 6.6.2
    7 Stable tag: 2.4.0
     6Tested up to: 6.8.1
     7Stable tag: 2.4.1
    88Requires PHP: 5.4
    99License: GPLv2 or later
     
    9393== Changelog ==
    9494
    95 = 2.3.10 =
     95= 2.4.2 =
     96*Release Date - 29 Jun 2025*
     97* Better support for Cardcom & GravityForms
     98* Security fixes
     99
     100= 2.4.1 =
    96101*Release Date - 26 Jun 2025*
    97102* Security fix, XSS on admin.
    98 
    99 = 2.3.9 =
    100 *Release Date - 26 Jun 2025*
    101103* Security and bug fixes
    102104* Performance Improvment - Seperation of Front-end / Backend code
    103105* Fixing issue with Woocommerce Subscriptions forcing tokens on Woocommerce Checkout
    104106* Feature: shorten urls when Payment Gateway cannot handle standard url lengths
     107* Tested under PHP 8.4
    105108
    106109= 2.2.2 =
  • simple-payment/trunk/simple-payment-plugin.php

    r3318406 r3319619  
    44 * Plugin URI: https://simple-payment.yalla-ya.com
    55 * Description: Simple Payment enables integration with multiple payment gateways, and customize multiple payment forms.
    6  * Version: 2.4.0
     6 * Version: 2.4.1
    77 * Author: Ido Kobelkowsky / yalla ya!
    88 * Author URI: https://github.com/idokd
     
    4545
    4646    public static $table_name = 'sp_transactions';
     47    public static $table_name_metadata = 'sp_transactions_metadata';
     48   
    4749    public static $engines = [ 'PayPal', 'Cardcom', 'iCount', 'PayMe', 'iCredit', 'CreditGuard', 'Meshulam', 'YaadPay', 'Credit2000', 'Custom' ];
    4850
     
    275277        $status = false;
    276278        if ( $code = parent::status( array_merge( $data, $params ) ) ) {
     279            $params[ 'confirmation_code' ] = $code;
    277280            $status = self::update( $this->payment_id ? : $this->engine->transaction, [
    278281                'status' => self::TRANSACTION_SUCCESS,
     
    838841    }
    839842
     843    public function get_entry(  $id, $engine = null ){
     844        return( $this->fetch( $id, $engine ) );
     845    }
    840846
    841847    public function fetch( $id, $engine = null ) {
     
    10301036require_once( 'addons/gravityforms/init.php' );
    10311037
    1032 
    10331038//require_once('addons/recaptcha/init.php');
    10341039
  • simple-payment/trunk/vendor/autoload.php

    r3318371 r3319619  
    1515        }
    1616    }
    17     trigger_error(
    18         $err,
    19         E_USER_ERROR
    20     );
     17    throw new RuntimeException($err);
    2118}
    2219
  • simple-payment/trunk/vendor/composer/InstalledVersions.php

    r3318371 r3319619  
    2828{
    2929    /**
     30     * @var string|null if set (by reflection by Composer), this should be set to the path where this class is being copied to
     31     * @internal
     32     */
     33    private static $selfDir = null;
     34
     35    /**
    3036     * @var mixed[]|null
    3137     * @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}|array{}|null
    3238     */
    3339    private static $installed;
     40
     41    /**
     42     * @var bool
     43     */
     44    private static $installedIsLocalDir;
    3445
    3546    /**
     
    310321        self::$installed = $data;
    311322        self::$installedByVendor = array();
     323
     324        // when using reload, we disable the duplicate protection to ensure that self::$installed data is
     325        // always returned, but we cannot know whether it comes from the installed.php in __DIR__ or not,
     326        // so we have to assume it does not, and that may result in duplicate data being returned when listing
     327        // all installed packages for example
     328        self::$installedIsLocalDir = false;
     329    }
     330
     331    /**
     332     * @return string
     333     */
     334    private static function getSelfDir()
     335    {
     336        if (self::$selfDir === null) {
     337            self::$selfDir = strtr(__DIR__, '\\', '/');
     338        }
     339
     340        return self::$selfDir;
    312341    }
    313342
     
    323352
    324353        $installed = array();
     354        $copiedLocalDir = false;
    325355
    326356        if (self::$canGetVendors) {
     357            $selfDir = self::getSelfDir();
    327358            foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
     359                $vendorDir = strtr($vendorDir, '\\', '/');
    328360                if (isset(self::$installedByVendor[$vendorDir])) {
    329361                    $installed[] = self::$installedByVendor[$vendorDir];
     
    331363                    /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
    332364                    $required = require $vendorDir.'/composer/installed.php';
    333                     $installed[] = self::$installedByVendor[$vendorDir] = $required;
    334                     if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
    335                         self::$installed = $installed[count($installed) - 1];
     365                    self::$installedByVendor[$vendorDir] = $required;
     366                    $installed[] = $required;
     367                    if (self::$installed === null && $vendorDir.'/composer' === $selfDir) {
     368                        self::$installed = $required;
     369                        self::$installedIsLocalDir = true;
    336370                    }
     371                }
     372                if (self::$installedIsLocalDir && $vendorDir.'/composer' === $selfDir) {
     373                    $copiedLocalDir = true;
    337374                }
    338375            }
     
    351388        }
    352389
    353         if (self::$installed !== array()) {
     390        if (self::$installed !== array() && !$copiedLocalDir) {
    354391            $installed[] = self::$installed;
    355392        }
  • simple-payment/trunk/vendor/composer/installed.php

    r3318371 r3319619  
    44        'pretty_version' => 'dev-master',
    55        'version' => 'dev-master',
    6         'reference' => '8d70fa9f086df134f54cc8e70526cb888ea9b265',
     6        'reference' => '59fc00a8805a5e2566813aaee5fd97f5dada586c',
    77        'type' => 'project',
    88        'install_path' => __DIR__ . '/../../',
     
    7070            'pretty_version' => 'dev-master',
    7171            'version' => 'dev-master',
    72             'reference' => '8d70fa9f086df134f54cc8e70526cb888ea9b265',
     72            'reference' => '59fc00a8805a5e2566813aaee5fd97f5dada586c',
    7373            'type' => 'project',
    7474            'install_path' => __DIR__ . '/../../',
  • simple-payment/trunk/vendor/yalla-ya/simple-payment/Engines/Cardcom.php

    r3318371 r3319619  
    77use DateInterval;
    88
    9 if (!defined("ABSPATH")) {
     9if (!defined("ABSPATH") ) {
    1010  exit; // Exit if accessed directly
    1111}
     
    4949  const OPERATIONS = [ 1 => 'Charge', 2 => 'Charge & Token', 3 => 'Token (Charge Pending)', 4 => 'Suspended Deal' ];
    5050  const DOC_TYPES = [ 1 => 'Invoice', 3 => 'Formal Receipt', 101 => 'Order Confirmation', 400 => 'Receipt' , 405 => 'Donation' ];
    51   const FIELD_STATUS = [ 'require' => 'Shown & Required', 'show' => 'Shown', 'hide' => 'Hidden'];
    52   const CREDIT_TYPES = [ 1 => 'Normal', 6 => 'Credit'];
    53   const DOC_OPERATIONS = [ 0 => 'No Invoice', 1 => 'Invoice', 2 => 'Forward (Do not show)'];
     51  const FIELD_STATUS = [ 'require' => 'Shown & Required', 'show' => 'Shown', 'hide' => 'Hidden' ];
     52  const CREDIT_TYPES = [ 1 => 'Normal', 6 => 'Credit' ];
     53  const DOC_OPERATIONS = [ 0 => 'No Invoice', 1 => 'Invoice', 2 => 'Forward (Do not show)' ];
    5454
    5555  public function __construct( $params = null, $handler = null, $sandbox = true ) {
     
    5959
    6060  public function process( $params ) {
    61     //header("Location: ".$params['url']);
     61    //header("Location: ".$params[ 'url' ]);
    6262    //return(true);
    6363    return( $params[ 'url' ] );
     
    7474      $post[ 'username' ] = $this->username;
    7575    }
    76     //$post['terminalnumber'] = $this->terminal;
    77     //$post['username'] = $this->username;
     76    //$post[ 'terminalnumber' ] = $this->terminal;
     77    //$post[ 'username' ] = $this->username;
    7878    $post[ 'lowprofilecode' ] = $this->transaction;
    7979    $post[ 'codepage' ] = 65001;
     
    106106        'transaction_id' => $this->transaction,
    107107        'url' => $this->api[ 'indicator_request' ],
    108         'status' => isset( $response[ 'OperationResponse' ] ) ? $response[ 'OperationResponse' ] : ( isset( $response[ 'DealResponse' ] ) ? $response[ 'DealResponse' ] : ''),
     108        'status' => isset( $response[ 'OperationResponse' ] ) ? $response[ 'OperationResponse' ] : ( isset( $response[ 'DealResponse' ] ) ? $response[ 'DealResponse' ] : '' ),
    109109        'description' => isset( $response[ 'OperationResponseText' ] ) ? $response[ 'OperationResponseText' ] : $response[ 'Description' ],
    110110        'request' => json_encode( $post ),
     
    117117    switch( intval( $operation ) ) {
    118118      case 1:
    119         $code = $response[ 'DealResponse' ];
    120         if ( isset( $response[ 'OperationResponse' ] ) && $response[ 'OperationResponse' ] == '0' && isset( $response[ 'DealResponse' ] ) && $response['DealResponse'] == '0' ) {
     119        $code = $response[ 'InternalDealNumber' ];
     120        if ( isset( $response[ 'OperationResponse' ] ) && $response[ 'OperationResponse' ] == '0' && isset( $response[ 'DealResponse' ] ) && $response[ 'DealResponse' ] == '0' ) {
    121121          $this->confirmation_code = $code;
    122122        }
     
    125125      case 2:
    126126        $code = $response[ 'TokenResponse' ];
    127         if ( isset( $response[ 'OperationResponse' ] ) && $response[ 'OperationResponse' ] == '0' && isset( $response[ 'DealResponse' ] ) && $response[ 'DealResponse' ] == '0' && isset( $response[ 'TokenResponse' ] ) && $response[ 'TokenResponse' ] == '0') {
     127        if ( isset( $response[ 'OperationResponse' ] ) && $response[ 'OperationResponse' ] == '0' && isset( $response[ 'DealResponse' ] ) && $response[ 'DealResponse' ] == '0' && isset( $response[ 'TokenResponse' ] ) && $response[ 'TokenResponse' ] == '0' ) {
    128128          $this->confirmation_code = $code;
    129129        }
     
    149149      'url' => ':callback',
    150150      'status' => isset( $params[ 'ResposeCode' ] ) ? $params[ 'ResposeCode' ] : $params[ 'ResponseCode' ],
    151       'description' => isset( $params[  'OperationResponseText' ] ) ? $params[  'OperationResponseText  '] : $params['Description'],
     151      'description' => isset( $params[  'OperationResponseText' ] ) ? $params[  'OperationResponseText  ' ] : $params[ 'Description' ],
    152152      'request' => json_encode( $params ),
    153153      'response' => null
     
    156156  }
    157157
    158   public function status($params) {
    159     parent::status($params);
    160     $this->transaction = $params['lowprofilecode'];
    161     $this->save([
     158  public function status( $params ) {
     159    parent::status( $params );
     160    $this->transaction = $params[ 'lowprofilecode' ];
     161    $this->save( [
    162162      'transaction_id' => $this->transaction,
    163       'url' => $_SERVER["REQUEST_URI"],
    164       'status' => isset($params['OperationResponse']) ? $params['OperationResponse'] : $params['DealResponse'],
    165       'description' => isset($params['OperationResponseText']) ? $params['OperationResponseText'] : $params['Description'],
    166       'request' => json_encode($_REQUEST),
     163      'url' => $_SERVER[ 'REQUEST_URI' ],
     164      'status' => isset( $params[ 'OperationResponse' ] ) ? $params[ 'OperationResponse' ] : $params[ 'DealResponse' ],
     165      'description' => isset( $params[ 'OperationResponseText' ] ) ? $params[ 'OperationResponseText' ] : $params[ 'Description' ],
     166      'request' => json_encode( $_REQUEST ),
    167167      'response' => null
    168     ]);
     168    ] );
    169169    $post = [];
    170170    if ( !$this->sandbox ) {
    171       $post['terminalnumber'] = $this->param_part($params);
    172       $post['username'] = $this->param_part($params, 'username');
     171      $post[ 'terminalnumber' ] = $this->param_part( $params );
     172      $post[ 'username' ] = $this->param_part( $params, 'username' );
    173173    } else {
    174       $post['terminalnumber'] = $this->terminal;
    175       $post['username'] = $this->username;
    176     }
    177     $post['lowprofilecode'] = $params['lowprofilecode'];
    178     $status = $this->post($this->api['indicator_request'], $post);
    179     parse_str($status, $status);
    180     //$this->transaction = $params['lowprofilecode'];
     174      $post[ 'terminalnumber' ] = $this->terminal;
     175      $post[ 'username' ] = $this->username;
     176    }
     177    $post[ 'lowprofilecode' ] = $params[ 'lowprofilecode' ];
     178    $status = $this->post( $this->api[ 'indicator_request' ], $post);
     179    parse_str( $status, $status );
     180    //$this->transaction = $params[ 'lowprofilecode' ];
    181181
    182182    // TODO: fetch VISA, YEAR, MONTH, ID???
     
    184184    if ( isset( $status[ 'Token' ] ) && $status[ 'Token' ] ) {
    185185      $token = [
    186           'token' => $status['Token'],
    187           SimplePayment::CARD_OWNER => $status['CardOwnerID'],
    188           SimplePayment::CARD_EXPIRY_YEAR => $status['CardValidityYear'],
    189           SimplePayment::CARD_EXPIRY_MONTH => $status['CardValidityMonth'],
     186          'token' => $status[ 'Token' ],
     187          SimplePayment::CARD_OWNER => $status[ 'CardOwnerID' ],
     188          SimplePayment::CARD_EXPIRY_YEAR => $status[ 'CardValidityYear' ],
     189          SimplePayment::CARD_EXPIRY_MONTH => $status[ 'CardValidityMonth' ],
    190190        //  'card_type' => '',
    191           'expiry' => $status['TokenExDate'],
     191          'expiry' => $status[ 'TokenExDate' ],
    192192      ];
    193193    }
    194194    $response = $status;
    195195    $this->confirmation_code = isset( $response[ 'InternalDealNumber' ] ) ? $response[ 'InternalDealNumber' ] : null;
    196     $this->save([
     196    $this->save( [
    197197      'transaction_id' => $this->transaction,
    198       'url' => $this->api['indicator_request'],
    199       'status' => isset($response['OperationResponse']) ? $response['OperationResponse'] : $response['DealResponse'],
    200       'description' => isset($response['OperationResponseText']) ? $response['OperationResponseText'] : $response['Description'],
    201       'request' => json_encode($post),
    202       'response' => json_encode($response),
     198      'url' => $this->api[ 'indicator_request' ],
     199      'status' => isset( $response[ 'OperationResponse' ] ) ? $response[ 'OperationResponse' ] : $response[ 'DealResponse' ],
     200      'description' => isset( $response[ 'OperationResponseText' ] ) ? $response[ 'OperationResponseText' ] : $response[ 'Description' ],
     201      'request' => json_encode( $post ),
     202      'response' => json_encode( $response ),
    203203      'token' => $token
    204     ]);
    205     if (!isset($response['OperationResponse']) || $response['OperationResponse'] != 0) {
    206       throw new Exception(isset($response['OperationResponseText']) ? $response['OperationResponseText'] : $response['Description'], isset($response['OperationResponse']) ? $response['OperationResponse'] : $response['DealResponse']);
    207     }
    208     if ($params['Operation'] == 2 && isset($params['payments']) && $params['payments'] == "monthly") {
    209       if ($this->param('recurr_at') == 'status' && $this->param('reurring') == 'provider') $this->recur_by_provider($params);
     204    ] );
     205    if ( !isset( $response[ 'OperationResponse' ]) || $response[ 'OperationResponse' ] != 0 ) {
     206      throw new Exception( isset( $response[ 'OperationResponseText' ] ) ? $response[ 'OperationResponseText' ] : $response[ 'Description' ], isset( $response[ 'OperationResponse' ] ) ? $response[ 'OperationResponse' ] : $response[ 'DealResponse' ] );
     207    }
     208    if ( $params[ 'Operation' ] == 2 && isset( $params[ 'payments' ] ) && $params[ 'payments' ] == 'monthly' ) {
     209      if ( $this->param( 'recurr_at' ) == 'status' && $this->param( 'reurring' ) == 'provider' ) $this->recur_by_provider( $params );
    210210    }
    211211    return( $this->confirmation_code );
     
    213213
    214214  public function post_process($params) {
    215     $this->transaction = isset( $_REQUEST['lowprofilecode'] ) ? $_REQUEST['lowprofilecode'] : $params[ 'transaction_id' ];
     215    $this->transaction = isset( $_REQUEST[ 'lowprofilecode' ] ) ? $_REQUEST[ 'lowprofilecode' ] : $params[ 'transaction_id' ];
    216216    $response = $_REQUEST;
    217217    $this->save([
    218218      'transaction_id' => $this->transaction,
    219219      'url' => ':post_process',
    220       'status' => isset($response['ResponseCode']) ? $response['ResponseCode'] : $response['response_code'],
    221       'description' => isset($response['Description']) ? $response['Description'] : null,
     220      'status' => isset($response[ 'ResponseCode' ]) ? $response[ 'ResponseCode' ] : $response[ 'response_code' ],
     221      'description' => isset($response[ 'Description' ]) ? $response[ 'Description' ] : null,
    222222      'request' => json_encode($params),
    223223      'response' => json_encode($response)
    224224    ]);
    225     if ($params['Operation'] == 2 && isset($params['payments']) && $params['payments'] == "monthly") {
    226       if ($this->param('recurr_at') == 'post' && $this->param('reurring') == 'provider') return($this->recur_by_provider($params));
     225    if ($params[ 'Operation' ] == 2 && isset($params[ 'payments' ]) && $params[ 'payments' ] == "monthly") {
     226      if ($this->param( 'recurr_at' ) == 'post' && $this->param( 'reurring' ) == 'provider' ) return($this->recur_by_provider($params) );
    227227    }
    228228    // TODO: update confirmation code con status
    229     //$this->confirmation_code = $response['confirmation_code'];
     229    //$this->confirmation_code = $response[ 'confirmation_code' ];
    230230    return( $_REQUEST[ 'ResponeCode' ] == 0 );
    231231  }
     
    254254    $post[ 'APILevel' ] = $this->api[ 'version' ];
    255255    if ( !$this->sandbox ) {
    256       $post[ 'TerminalNumber'] = $this->param_part( $params );
    257       $post[ 'UserName'] = $this->param_part( $params, 'username' );
    258       // $this->password = $this->param_part($params, 'password');
    259       // $post['Password'] = $this->password;
     256      $post[ 'TerminalNumber' ] = $this->param_part( $params );
     257      $post[ 'UserName' ] = $this->param_part( $params, 'username' );
     258      // $this->password = $this->param_part($params, 'password' );
     259      // $post[ 'Password' ] = $this->password;
    260260    } else {
    261261      $post[ 'TerminalNumber' ] = $this->terminal;
     
    271271
    272272
    273     $post['ProductName'] = $params['product'];
    274     $post['SumToBill'] = $params['amount'];
    275 
    276     if (isset($params[SimplePayment::CARD_OWNER]) && $params[SimplePayment::CARD_OWNER]) $post['CardOwnerName'] = $params[SimplePayment::CARD_OWNER];
    277     if (!isset($post['CardOwnerName']) && isset($params['full_name']) && $params['full_name']) $post['CardOwnerName'] = $params['full_name']; // card_holder
    278 
    279     if (isset($params['phone']) && $params['phone']) $post['CardOwnerPhone'] = $params['phone'];
    280     if (isset($params['email']) && $params['email']) $post['CardOwnerEmail'] = $params['email'];
    281 
    282     if (isset($params['payment_id']) && $params['payment_id']) $post['ReturnValue'] = $params['payment_id'];
    283 
    284     $post['codepage'] = 65001; // Codepage fixed to enable hebrew
    285     $currency = isset($params[SimplePayment::CURRENCY]) && $params[SimplePayment::CURRENCY] ? $params[SimplePayment::CURRENCY] : $this->param('currency');
    286     if ($currency) {
    287       if ($currency = self::CURRENCIES[$currency]) $post['CoinID'] = $currency;
    288       else throw new Exception('CURRENCY_NOT_SUPPORTED_BY_ENGINE', 500);
    289     }
    290 
    291     $language = isset($params['language']) ? $params['language'] : $this->param('language');
    292     if ($language != '') $post['Language'] = $language;
     273    $post[ 'ProductName' ] = $params[ 'product' ];
     274    $post[ 'SumToBill' ] = $params[ 'amount' ];
     275
     276    if (isset($params[SimplePayment::CARD_OWNER]) && $params[SimplePayment::CARD_OWNER]) $post[ 'CardOwnerName' ] = $params[SimplePayment::CARD_OWNER];
     277    if (!isset($post[ 'CardOwnerName' ]) && isset($params[ 'full_name' ]) && $params[ 'full_name' ]) $post[ 'CardOwnerName' ] = $params[ 'full_name' ]; // card_holder
     278
     279    if (isset($params[ 'phone' ]) && $params[ 'phone' ]) $post[ 'CardOwnerPhone' ] = $params[ 'phone' ];
     280    if (isset($params[ 'email' ]) && $params[ 'email' ]) $post[ 'CardOwnerEmail' ] = $params[ 'email' ];
     281
     282    if (isset($params[ 'payment_id' ]) && $params[ 'payment_id' ]) $post[ 'ReturnValue' ] = $params[ 'payment_id' ];
     283
     284    $post[ 'codepage' ] = 65001; // Codepage fixed to enable hebrew
     285    $currency = isset( $params[ SimplePayment::CURRENCY ] ) && $params[ SimplePayment::CURRENCY ] ? $params[ SimplePayment::CURRENCY ] : $this->param( 'currency' );
     286    if ( $currency ) {
     287      if ( $currency = self::CURRENCIES[ $currency ] ) $post[ 'CoinID' ] = $currency;
     288      else throw new Exception( 'CURRENCY_NOT_SUPPORTED_BY_ENGINE', 500 );
     289    }
     290
     291    $language = isset( $params[ 'language' ] ) ? $params[ 'language' ] : $this->param( 'language' );
     292    if ($language != '' ) $post[ 'Language' ] = $language;
    293293
    294294    if ( !isset( $params[ 'payments' ] ) || ( isset( $params[ 'payments' ] ) && $params[ 'payments' ] ) ) {
     
    302302    }
    303303
    304     $post['SuccessRedirectUrl'] = $this->url(SimplePayment::OPERATION_SUCCESS, $params);
    305     $post['ErrorRedirectUrl'] = $this->url(SimplePayment::OPERATION_ERROR, $params);
    306     $post['IndicatorUrl'] = $this->url(SimplePayment::OPERATION_STATUS, $params);
    307     $post['CancelUrl'] = $this->url(SimplePayment::OPERATION_CANCEL, $params);
    308     if ($this->param('css') != '') $post[ 'CSSUrl' ] = $this->callback.(strpos($this->callback, '?') !== false ? '&' : '?').'op=css';
    309 
    310     $post['CancelType'] = $this->cancelType;
    311 
    312     $creditType = $this->param('credit_type');
    313     if ($creditType != '') $post['CreditType'] = $creditType;
    314 
    315     $show = $this->param('show_invoice_operation');
    316     if ($operation != 3 && $show != '') $post['InvoiceHeadOperation'] = $operation == 3 ? 0 : $show;
    317 
    318     $show = $this->param('show_invoice_info');
    319     if ($operation != 3 && $show != '') $post['ShowInvoiceHead'] = $show;
    320 
    321     $docType = $this->param('doc_type');
    322     if ($operation != 3 && $docType != '') $post['DocTypeToCreate'] = $docType;
    323 
    324     $field = $this->param('field_name');
    325     if ($field != '') {
    326         $post['HideCardOwnerName'] = $field == 'hide' ? 'true' : 'false';
    327     }
    328 
    329     $field = $this->param('field_phone');
    330     if ($field != '') {
    331         $post['ReqCardOwnerPhone'] = $field == 'require' ? 'true' : 'false';
    332         $post['ShowCardOwnerPhone'] = $field == 'show' || $field == 'require' ? 'true' : 'false';
    333     }
    334 
    335     $field = $this->param('field_email');
    336     if ($field != '') {
    337         $post['ReqCardOwnerEmail'] = $field == 'require' ? 'true' : 'false';
    338         $post['ShowCardOwnerEmail'] = $field == 'show' || $field == 'require' ? 'true' : 'false';
     304    $post[ 'SuccessRedirectUrl' ] = $this->url( SimplePayment::OPERATION_SUCCESS, $params );
     305    $post[ 'ErrorRedirectUrl' ] = $this->url( SimplePayment::OPERATION_ERROR, $params );
     306    $post[ 'IndicatorUrl' ] = $this->url( SimplePayment::OPERATION_STATUS, $params );
     307    $post[ 'CancelUrl' ] = $this->url( SimplePayment::OPERATION_CANCEL, $params );
     308    if ( $this->param( 'css' ) != '' ) $post[ 'CSSUrl' ] = $this->callback . ( strpos( $this->callback, '?' ) !== false ? '&' : '?' ) . 'op=css';
     309
     310    $post[ 'CancelType' ] = $this->cancelType;
     311
     312    $creditType = $this->param( 'credit_type' );
     313    if ( $creditType != '' ) $post[ 'CreditType' ] = $creditType;
     314
     315    $show = $this->param( 'show_invoice_operation' );
     316    if ( $operation != 3 && $show != '' ) $post[ 'InvoiceHeadOperation' ] = $operation == 3 ? 0 : $show;
     317
     318    $show = $this->param( 'show_invoice_info' );
     319    if ( $operation != 3 && $show != '' ) $post[ 'ShowInvoiceHead' ] = $show;
     320
     321    $docType = $this->param( 'doc_type' );
     322    if ( $operation != 3 && $docType != '' ) $post[ 'DocTypeToCreate' ] = $docType;
     323
     324    $field = $this->param( 'field_name' );
     325    if ( $field != '' ) {
     326        $post[ 'HideCardOwnerName' ] = $field == 'hide' ? 'true' : 'false';
     327    }
     328
     329    $field = $this->param( 'field_phone' );
     330    if ( $field != '' ) {
     331        $post[ 'ReqCardOwnerPhone' ] = $field == 'require' ? 'true' : 'false';
     332        $post[ 'ShowCardOwnerPhone' ] = $field == 'show' || $field == 'require' ? 'true' : 'false';
     333    }
     334
     335    $field = $this->param( 'field_email' );
     336    if ( $field != '' ) {
     337        $post[ 'ReqCardOwnerEmail' ] = $field == 'require' ? 'true' : 'false';
     338        $post[ 'ShowCardOwnerEmail' ] = $field == 'show' || $field == 'require' ? 'true' : 'false';
    339339    }
    340340   
    341     if ((!isset($params['payments']) || $params['payments'] != "monthly") && $this->param('hide_user_id')) $post['HideCreditCardUserId'] = $this->param('hide_user_id') == 'true' ? 'true' : 'false';
    342 
    343     if ($operation != 3 && isset($params['company']) && $params['company']) $post['InvoiceHead.CustName'] = $params['company'];
    344     if ($operation != 3 && !isset($post['InvoiceHead.CustName']) && isset($params['full_name']) && $params['full_name']) $post['InvoiceHead.CustName'] = $params['full_name'];
    345     if ($operation != 3) $post = array_merge($post, $this->document(array_merge($params, ['language' => $language, 'currency' => $currency])));
     341    if ( ( !isset( $params[ 'payments' ]) || $params[ 'payments' ] != "monthly" ) && $this->param( 'hide_user_id' ) ) $post[ 'HideCreditCardUserId' ] = $this->param( 'hide_user_id' ) == 'true' ? 'true' : 'false';
     342
     343    if ( $operation != 3 && isset( $params[ 'company' ]) && $params[ 'company' ]) $post[ 'InvoiceHead.CustName' ] = $params[ 'company' ];
     344    if ( $operation != 3 && !isset( $post[ 'InvoiceHead.CustName' ]) && isset( $params[ 'full_name' ]) && $params[ 'full_name' ]) $post[ 'InvoiceHead.CustName' ] = $params[ 'full_name' ];
     345    if ( $operation != 3 ) $post = array_merge( $post, $this->document( array_merge( $params, [ 'language' => $language, 'currency' => $currency ] ) ));
    346346
    347347    // TODO: Analyze how to use those parameters
     
    365365    // SuspendedDealJValidateType
    366366    // SuspendedDealGroup
    367     $status = $this->post($this->api['payment_request'], $post);
    368     parse_str($status, $status);
    369     $status['url'] = $this->param('method') == 'paypal' ? $status['PayPalUrl'] : $status['url'];
    370     $this->transaction = $this->transaction ? : $status['LowProfileCode'];
     367    $status = $this->post( $this->api[ 'payment_request' ], $post );
     368    parse_str( $status, $status );
     369    $status[ 'url' ] = $this->param( 'method' ) == 'paypal' ? $status[ 'PayPalUrl' ] : $status[ 'url' ];
     370    $this->transaction = $this->transaction ? : $status[ 'LowProfileCode' ];
    371371    $response = $status;
    372     $this->save([
     372    $this->save( [
    373373      'transaction_id' => $this->transaction,
    374       'url' => $this->api['payment_request'],
    375       'status' => isset($response['ResponseCode']) ? $response['ResponseCode'] : $response['response_code'],
    376       'description' => isset($response['Description']) ? $response['Description'] : null,
    377       'request' => json_encode($post),
    378       'response' => json_encode($response)
    379     ]);
    380     if (isset($status['LowProfileCode']) && $status['LowProfileCode']) $this->transaction = $status['LowProfileCode'];
    381     if (isset($status['ResponseCode']) && $status['ResponseCode'] != 0) {
    382       throw new Exception($status['Description'], $status['ResponseCode']);
    383     }
    384     return($response);
     374      'url' => $this->api[ 'payment_request' ],
     375      'status' => isset( $response[ 'ResponseCode' ]) ? $response[ 'ResponseCode' ] : $response[ 'response_code' ],
     376      'description' => isset( $response[ 'Description' ]) ? $response[ 'Description' ] : null,
     377      'request' => json_encode( $post ),
     378      'response' => json_encode( $response )
     379    ] );
     380    if ( isset( $status[ 'LowProfileCode' ] ) && $status[ 'LowProfileCode' ] ) $this->transaction = $status[ 'LowProfileCode' ];
     381    if ( isset( $status[ 'ResponseCode' ] ) && $status[ 'ResponseCode' ] != 0 ) {
     382      throw new Exception( $status[ 'Description' ], $status[ 'ResponseCode' ] );
     383    }
     384    return( $response );
    385385  }
    386386
     
    389389   
    390390    if (!$this->sandbox) {
    391       $post['TerminalNumber'] = $this->param_part($params);
    392       $post['UserName'] = $this->param_part($params, 'username');
    393       $terminals = $this->param('terminal');
    394       $terminals = explode(';', $terminals);
     391      $post[ 'TerminalNumber' ] = $this->param_part($params);
     392      $post[ 'UserName' ] = $this->param_part($params, 'username' );
     393      $terminals = $this->param( 'terminal' );
     394      $terminals = explode( ';', $terminals);
    395395    } else {
    396       $post['TerminalNumber'] = $this->terminal;
    397       $post['UserName'] = $this->username;
    398     }
    399 
    400     if ($this->param('recurring_terminal')) $post['RecurringPayments.ChargeInTerminal'] = $this->param('recurring_terminal');
    401     $post['Operation'] = $this->param('reurring_operation');
    402     $post['LowProfileDealGuid'] = isset($params['lowprofilecode']) ? $params['lowprofilecode'] : $params['transaction_id'];
     396      $post[ 'TerminalNumber' ] = $this->terminal;
     397      $post[ 'UserName' ] = $this->username;
     398    }
     399
     400    if ($this->param( 'recurring_terminal' ) ) $post[ 'RecurringPayments.ChargeInTerminal' ] = $this->param( 'recurring_terminal' );
     401    $post[ 'Operation' ] = $this->param( 'reurring_operation' );
     402    $post[ 'LowProfileDealGuid' ] = isset($params[ 'lowprofilecode' ]) ? $params[ 'lowprofilecode' ] : $params[ 'transaction_id' ];
    403403   
    404     if ($this->param('department_id')) $post['RecurringPayments.DepartmentId'] = $this->param('department_id');
    405     //if (isset($params['payment_id']) && $params['payment_id']) $post['Account.SiteUniqueId'] = $params['payment_id'];
    406 
    407     if (isset($params['payment_id']) && $params['payment_id']) $post['RecurringPayments.ReturnValue'] = $params['payment_id'];
    408 
    409     $post['RecurringPayments.FlexItem.Price'] = $params['amount'];
    410     $post['RecurringPayments.FlexItem.InvoiceDescription'] = isset($params['product']) ? $params['product'] : $params['concept'];
    411     $post['RecurringPayments.InternalDecription'] = isset($params['product']) ? $params['product'] : $params['concept'];
     404    if ($this->param( 'department_id' ) ) $post[ 'RecurringPayments.DepartmentId' ] = $this->param( 'department_id' );
     405    //if (isset($params[ 'payment_id' ]) && $params[ 'payment_id' ]) $post[ 'Account.SiteUniqueId' ] = $params[ 'payment_id' ];
     406
     407    if (isset($params[ 'payment_id' ]) && $params[ 'payment_id' ]) $post[ 'RecurringPayments.ReturnValue' ] = $params[ 'payment_id' ];
     408
     409    $post[ 'RecurringPayments.FlexItem.Price' ] = $params[ 'amount' ];
     410    $post[ 'RecurringPayments.FlexItem.InvoiceDescription' ] = isset($params[ 'product' ]) ? $params[ 'product' ] : $params[ 'concept' ];
     411    $post[ 'RecurringPayments.InternalDecription' ] = isset($params[ 'product' ]) ? $params[ 'product' ] : $params[ 'concept' ];
    412412   
    413413    if (isset($params[SimplePayment::CARD_OWNER]) && $params[SimplePayment::CARD_OWNER]) {
    414       $post['Account.ContactName'] = $params[SimplePayment::CARD_OWNER];
    415     }
    416     if (!isset($post['CardOwnerName']) && isset($params['full_name']) && $params['full_name']) {
    417       $post['Account.ContactName'] = $params['full_name']; // card_holder
    418     }
    419 
    420     if (isset($params['first_name']) && $params['first_name']) $post['Account.FirstName'] = $params['first_name'];
    421     if (isset($params['last_name']) && $params['last_name']) $post['Account.FirstName'] = (isset($post['Account.FirstName']) && $post['Account.FirstName'] ? ' ' : '').$params['last_name'];
    422 
    423     if (isset($params['phone']) && $params['phone']) $post['Account.PhLine'] = $params['phone'];
    424     if (isset($params['mobile']) && $params['mobile']) $post['Account.PhMobile'] = $params['mobile'];
    425     if (isset($params['email']) && $params['email']) $post['Account.Email'] = $params['email'];
    426 
    427     if (isset($params['address']) && $params['address']) $post['Account.Street1'] = $params['address'];
    428     if (isset($params['address2']) && $params['address2']) $post['Account.Street2'] = $params['address2'];
    429     if (isset($params['zipcode']) && $params['zipcode']) $post['Account.ZipCode'] = $params['zipcode'];
    430     if (isset($params['city']) && $params['city']) $post['Account.City'] = $params['city'];
    431 
    432     if (isset($params['comment']) && $params['comment']) $post['Account.Comments'] = $params['comment'];
    433 
    434     if (isset($params['tax_id']) && $params['tax_id']) $post['Account.RegisteredBusinessNumber'] = $params['tax_id'];
    435 
    436     if ($this->param('vat_free')) $post['Account.VatFree'] = 'true';
    437 
    438     $language = isset($params['language']) ? $params['language'] : $this->param('language');
    439     if ($language != '') $post['Account.IsDocumentLangEnglish'] = $language == 'he' ? 'false' : 'true';
    440 
    441     $currency = isset($params['currency']) && $params['currency'] ? $params['currency'] : $this->param('currency');
    442     if ($currency != '') {
    443       if ($currency = self::CURRENCIES[$currency]) $post['RecurringPayments.FinalDebitCoinId'] = $currency;
    444       else throw new Exception('CURRENCY_NOT_SUPPORTED_BY_ENGINE', 500);
    445     }
    446 
    447     $post['codepage'] = 65001; // Codepage fixed to enable hebrew
     414      $post[ 'Account.ContactName' ] = $params[SimplePayment::CARD_OWNER];
     415    }
     416    if (!isset($post[ 'CardOwnerName' ]) && isset($params[ 'full_name' ]) && $params[ 'full_name' ]) {
     417      $post[ 'Account.ContactName' ] = $params[ 'full_name' ]; // card_holder
     418    }
     419
     420    if (isset($params[ 'first_name' ]) && $params[ 'first_name' ]) $post[ 'Account.FirstName' ] = $params[ 'first_name' ];
     421    if (isset($params[ 'last_name' ]) && $params[ 'last_name' ]) $post[ 'Account.FirstName' ] = (isset($post[ 'Account.FirstName' ]) && $post[ 'Account.FirstName' ] ? ' ' : '' ).$params[ 'last_name' ];
     422
     423    if (isset($params[ 'phone' ]) && $params[ 'phone' ]) $post[ 'Account.PhLine' ] = $params[ 'phone' ];
     424    if (isset($params[ 'mobile' ]) && $params[ 'mobile' ]) $post[ 'Account.PhMobile' ] = $params[ 'mobile' ];
     425    if (isset($params[ 'email' ]) && $params[ 'email' ]) $post[ 'Account.Email' ] = $params[ 'email' ];
     426
     427    if (isset($params[ 'address' ]) && $params[ 'address' ]) $post[ 'Account.Street1' ] = $params[ 'address' ];
     428    if (isset($params[ 'address2' ]) && $params[ 'address2' ]) $post[ 'Account.Street2' ] = $params[ 'address2' ];
     429    if (isset($params[ 'zipcode' ]) && $params[ 'zipcode' ]) $post[ 'Account.ZipCode' ] = $params[ 'zipcode' ];
     430    if (isset($params[ 'city' ]) && $params[ 'city' ]) $post[ 'Account.City' ] = $params[ 'city' ];
     431
     432    if (isset($params[ 'comment' ]) && $params[ 'comment' ]) $post[ 'Account.Comments' ] = $params[ 'comment' ];
     433
     434    if (isset($params[ 'tax_id' ]) && $params[ 'tax_id' ]) $post[ 'Account.RegisteredBusinessNumber' ] = $params[ 'tax_id' ];
     435
     436    if ($this->param( 'vat_free' ) ) $post[ 'Account.VatFree' ] = 'true';
     437
     438    $language = isset($params[ 'language' ]) ? $params[ 'language' ] : $this->param( 'language' );
     439    if ($language != '' ) $post[ 'Account.IsDocumentLangEnglish' ] = $language == 'he' ? 'false' : 'true';
     440
     441    $currency = isset($params[ 'currency' ]) && $params[ 'currency' ] ? $params[ 'currency' ] : $this->param( 'currency' );
     442    if ($currency != '' ) {
     443      if ($currency = self::CURRENCIES[$currency]) $post[ 'RecurringPayments.FinalDebitCoinId' ] = $currency;
     444      else throw new Exception( 'CURRENCY_NOT_SUPPORTED_BY_ENGINE', 500);
     445    }
     446
     447    $post[ 'codepage' ] = 65001; // Codepage fixed to enable hebrew
    448448    // month from now 28 days
    449449    $date = new DateTime();
    450     $date->add(new DateInterval('P28D')); // P1D means a period of 28 day
    451     $post['RecurringPayments.NextDateToBill'] = $date->format('d/m/Y');
     450    $date->add(new DateInterval( 'P28D' ) ); // P1D means a period of 28 day
     451    $post[ 'RecurringPayments.NextDateToBill' ] = $date->format( 'd/m/Y' );
    452452
    453453    $limit = $this->param( 'recurring_total' );
    454     $post['RecurringPayments.TotalNumOfBills'] = $limit ? : 999999;
    455 
    456     $interval = $this->param('recurring_interval');
    457     if ($interval) $post['TimeIntervalId'] = $interval;
     454    $post[ 'RecurringPayments.TotalNumOfBills' ] = $limit ? : 999999;
     455
     456    $interval = $this->param( 'recurring_interval' );
     457    if ($interval) $post[ 'TimeIntervalId' ] = $interval;
    458458 
    459     $docType = $this->param('doc_type');
    460     if ($docType != '') $post['RecurringPayments.DocTypeToCreate'] = $docType;
    461 
    462     $post['RecurringPayments.FlexItem.IsPriceIncludeVat'] = 'true'; // Must be true - API requirement
     459    $docType = $this->param( 'doc_type' );
     460    if ($docType != '' ) $post[ 'RecurringPayments.DocTypeToCreate' ] = $docType;
     461
     462    $post[ 'RecurringPayments.FlexItem.IsPriceIncludeVat' ] = 'true'; // Must be true - API requirement
    463463    // TODO: assure to verifiy first_name / lasstname or use full name
    464     if (isset($params['full_name']) && trim($params['full_name'])) $post['Account.CompanyName'] = trim($params['full_name']);
    465     if (!isset($post['Account.CompanyName']) && isset($params['first_name']) && trim($params['first_name'])) $post['Account.CompanyName'] = trim($params['first_name'].(isset($params['last_name']) ? ' '.$params['last_name'] : ''));
    466     if (!isset($post['Account.CompanyName']) && isset($params['last_name']) && trim($params['last_name'])) $post['Account.CompanyName'] = trim($params['last_name']);
    467     if (isset($params['company']) && trim($params['company'])) $post['Account.CompanyName'] = trim($params['company']);
     464    if (isset($params[ 'full_name' ]) && trim($params[ 'full_name' ]) ) $post[ 'Account.CompanyName' ] = trim($params[ 'full_name' ]);
     465    if (!isset($post[ 'Account.CompanyName' ]) && isset($params[ 'first_name' ]) && trim($params[ 'first_name' ]) ) $post[ 'Account.CompanyName' ] = trim($params[ 'first_name' ].(isset($params[ 'last_name' ]) ? ' '.$params[ 'last_name' ] : '' ) );
     466    if (!isset($post[ 'Account.CompanyName' ]) && isset($params[ 'last_name' ]) && trim($params[ 'last_name' ]) ) $post[ 'Account.CompanyName' ] = trim($params[ 'last_name' ]);
     467    if (isset($params[ 'company' ]) && trim($params[ 'company' ]) ) $post[ 'Account.CompanyName' ] = trim($params[ 'company' ]);
    468468    // Not in use:
    469469    //  Account.AccountId   ,
     
    471471    // Account.ForeignAccountNumber , RecurringPayments.IsActive   
    472472    // BankInfo.Bank     BankInfo.Branch    BankInfo.AccountNumber   BankInfo.Description   
    473     $status = $this->post($this->api['recurring_request'], $post);
     473    $status = $this->post($this->api[ 'recurring_request' ], $post);
    474474    parse_str($status, $status);
    475475    $response = $status;
    476476    $this->save([
    477477      'transaction_id' => $this->transaction,
    478       'url' => $this->api['recurring_request'],
    479       'status' => isset($response['ResponseCode']) ? $response['ResponseCode'] : $response['response_code'],
    480       'description' => isset($response['Description']) ? $response['Description'] : null,
     478      'url' => $this->api[ 'recurring_request' ],
     479      'status' => isset($response[ 'ResponseCode' ]) ? $response[ 'ResponseCode' ] : $response[ 'response_code' ],
     480      'description' => isset($response[ 'Description' ]) ? $response[ 'Description' ] : null,
    481481      'request' => json_encode($post),
    482482      'response' => json_encode($response)
     
    499499  public function recur( $params ) {
    500500    $this->transaction = self::uuid();
    501     //$this->transaction = $params['transaction_id'];
     501    //$this->transaction = $params[ 'transaction_id' ];
    502502    $this->confirmation_code = $this->charge( $params );
    503503    return( $this->confirmation_code );
     
    509509      $post[ 'terminalnumber' ] = $this->param_part( $params );
    510510      $post[ 'username' ] = $this->param_part( $params, 'username' );
    511      // $post['TokenToCharge.UserPassword'] = $this->param_part($params, 'password');
     511     // $post[ 'TokenToCharge.UserPassword' ] = $this->param_part($params, 'password' );
    512512    } else {
    513513      $post[ 'terminalnumber' ] = $this->terminal;
     
    515515    }
    516516
    517     if ($refund) $post['TokenToCharge.UserPassword'] = $this->password;
    518 
    519     $token = $params['token'] ? json_decode($params['token'], true) : null;
     517    if ($refund) $post[ 'TokenToCharge.UserPassword' ] = $this->password;
     518
     519    $token = $params[ 'token' ] ? json_decode($params[ 'token' ], true) : null;
    520520    if ($token) {
    521       $post['TokenToCharge.Token'] = $token['token'];//$this->transaction;
    522       if (isset($token[SimplePayment::CARD_EXPIRY_YEAR])) $post['TokenToCharge.CardValidityYear'] = $token[SimplePayment::CARD_EXPIRY_YEAR];
    523       if (isset($token[SimplePayment::CARD_EXPIRY_MONTH])) $post['TokenToCharge.CardValidityMonth'] = $token[SimplePayment::CARD_EXPIRY_MONTH];     
    524       if (isset($token[SimplePayment::CARD_OWNER_ID])) $post['TokenToCharge.IdentityNumber'] = $token[SimplePayment::CARD_OWNER_ID];
    525     }
    526     $post['TokenToCharge.SumToBill'] = $params['amount'];
    527 
    528     $currency = isset($params[SimplePayment::CURRENCY]) && $params[SimplePayment::CURRENCY] ? $params[SimplePayment::CURRENCY] : $this->param('currency');
    529     if ($currency != '') {
    530       if ($currency = self::CURRENCIES[$currency]) $post['CoinID'] = $currency;
    531       else throw new Exception('CURRENCY_NOT_SUPPORTED_BY_ENGINE', 500);
    532     }
    533 
    534     $post['TokenToCharge.CoinID'] = $currency;
    535 
    536 
    537 
    538 
    539     $language = $this->param('language');
    540     if ($language != '') $post['Language'] = $language;
     521      $post[ 'TokenToCharge.Token' ] = $token[ 'token' ];//$this->transaction;
     522      if (isset($token[SimplePayment::CARD_EXPIRY_YEAR]) ) $post[ 'TokenToCharge.CardValidityYear' ] = $token[SimplePayment::CARD_EXPIRY_YEAR];
     523      if (isset($token[SimplePayment::CARD_EXPIRY_MONTH]) ) $post[ 'TokenToCharge.CardValidityMonth' ] = $token[SimplePayment::CARD_EXPIRY_MONTH];     
     524      if (isset($token[SimplePayment::CARD_OWNER_ID]) ) $post[ 'TokenToCharge.IdentityNumber' ] = $token[SimplePayment::CARD_OWNER_ID];
     525    }
     526    $post[ 'TokenToCharge.SumToBill' ] = $params[ 'amount' ];
     527
     528    $currency = isset($params[SimplePayment::CURRENCY]) && $params[SimplePayment::CURRENCY] ? $params[SimplePayment::CURRENCY] : $this->param( 'currency' );
     529    if ($currency != '' ) {
     530      if ($currency = self::CURRENCIES[$currency]) $post[ 'CoinID' ] = $currency;
     531      else throw new Exception( 'CURRENCY_NOT_SUPPORTED_BY_ENGINE', 500);
     532    }
     533
     534    $post[ 'TokenToCharge.CoinID' ] = $currency;
     535
     536
     537
     538
     539    $language = $this->param( 'language' );
     540    if ($language != '' ) $post[ 'Language' ] = $language;
    541541
    542542    //  TokenToCharge.CardOwnerName
     
    547547
    548548
    549     if ($refund) $post['TokenToCharge.RefundInsteadOfCharge'] = $refund;
    550     if ($params['PAYMENTS'] == 'monthly') $post['TokenToCharge.IsAutoRecurringPayment'] = 'true';
    551 
    552     if (isset($params['approval_number']) && $params['approval_number']) $post['TokenToCharge.ApprovalNumber'] = $params['approval_number'];
    553 
    554 
    555     // $post = array_merge($post, $this->document(array_merge($params, ['language' => $language, 'currency' => $currency])));
    556 
    557     $status = $this->post($this->api['payment_recur'], $post);
     549    if ($refund) $post[ 'TokenToCharge.RefundInsteadOfCharge' ] = $refund;
     550    if ($params[ 'PAYMENTS' ] == 'monthly' ) $post[ 'TokenToCharge.IsAutoRecurringPayment' ] = 'true';
     551
     552    if (isset($params[ 'approval_number' ]) && $params[ 'approval_number' ]) $post[ 'TokenToCharge.ApprovalNumber' ] = $params[ 'approval_number' ];
     553
     554
     555    // $post = array_merge($post, $this->document(array_merge($params, [ 'language' => $language, 'currency' => $currency]) ));
     556
     557    $status = $this->post($this->api[ 'payment_recur' ], $post);
    558558    parse_str($status, $status);
    559559    $response = $status;
    560560    $this->save([
    561561      'transaction_id' => $this->transaction,
    562       'url' => $this->api['payment_recur'],
    563       'status' => isset($response['ResponseCode']) ? $response['ResponseCode'] : $response['response_code'],
    564       'description' => isset($response['Description']) ? $response['Description'] : null,
     562      'url' => $this->api[ 'payment_recur' ],
     563      'status' => isset($response[ 'ResponseCode' ]) ? $response[ 'ResponseCode' ] : $response[ 'response_code' ],
     564      'description' => isset($response[ 'Description' ]) ? $response[ 'Description' ] : null,
    565565      'request' => json_encode($post),
    566566      'response' => json_encode($response),
     
    568568    ]);
    569569    // InternalDealNumber
    570     return($response['ResponseCode'] == 0 ? $response['InternalDealNumber'] : false);
     570    return($response[ 'ResponseCode' ] == 0 ? $response[ 'InternalDealNumber' ] : false);
    571571    // Not in use:
    572572    // TokenToCharge.Salt, TokenToCharge.SumInStars, TokenToCharge.NumOfPayments
     
    581581  protected function document($params) {
    582582    $post = [];
    583     $language = $this->param('language');
    584     $currency = isset($params[SimplePayment::CURRENCY]) ? $params[SimplePayment::CURRENCY] : $this->param('currency');
    585     if ($language) $post['InvoiceHead.Languge'] = $params['language'];
    586     if ($currency) $post['InvoiceHead.CoinID'] = $params['currency'];
    587 
    588     if (isset($params['email']) && $params['email']) $post['InvoiceHead.Email'] = $params['email'];
     583    $language = $this->param( 'language' );
     584    $currency = isset($params[SimplePayment::CURRENCY]) ? $params[SimplePayment::CURRENCY] : $this->param( 'currency' );
     585    if ($language) $post[ 'InvoiceHead.Languge' ] = $params[ 'language' ];
     586    if ($currency) $post[ 'InvoiceHead.CoinID' ] = $params[ 'currency' ];
     587
     588    if (isset($params[ 'email' ]) && $params[ 'email' ]) $post[ 'InvoiceHead.Email' ] = $params[ 'email' ];
    589589   
    590     if (!$this->param('doc_details') || in_array($this->param('doc_details'), ['address', 'full'])) {
    591       if (isset($params['address']) && $params['address']) $post['InvoiceHead.CustAddresLine1'] = $params['address'];
    592       if (isset($params['address2']) && $params['address2']) $post['InvoiceHead.CustAddresLine2'] = $params['address2'];
    593       if (isset($params['city']) && $params['city']) $post['InvoiceHead.CustCity'] = $params['city'];
    594     }
    595     if (!$this->param('doc_details') || in_array($this->param('doc_details'), ['contact', 'full'])) {
    596       if (isset($params['phone']) && $params['phone']) $post['InvoiceHead.CustLinePH'] = $params['phone'];
    597       if (isset($params['mobile']) && $params['mobile']) $post['InvoiceHead.CustMobilePH'] = $params['mobile'];
    598     }
    599 
    600     if (isset($params['tax_id']) && $params['tax_id']) $post['InvoiceHead.CompID'] = $params['tax_id'];
    601     if (isset($params['comment']) && $params['comment']) $post['InvoiceHead.Comments'] = $params['comment'];
    602     if ($this->param('email_invoice')) $post['InvoiceHead.SendByEmail'] = 'true';
    603     if ($this->param('vat_free')) $post['InvoiceHead.ExtIsVatFree'] = 'true';
    604     if ($this->param('auto_create_account')) $post['InvoiceHead.IsAutoCreateUpdateAccount'] = 'true';
    605     if ($this->param('auto_load_account')) $post['InvoiceHead.IsLoadInfoFromAccountID'] = 'true';
    606     if ($this->param('department_id')) $post['InvoiceHead.DepartmentId'] = $this->param('department_id');
    607     //if ( isset($params['payment_id']) && $params['payment_id']) $post['InvoiceHead.SiteUniqueId'] = $params['payment_id'];
     590    if (!$this->param( 'doc_details' ) || in_array($this->param( 'doc_details' ), [ 'address', 'full' ]) ) {
     591      if (isset($params[ 'address' ]) && $params[ 'address' ]) $post[ 'InvoiceHead.CustAddresLine1' ] = $params[ 'address' ];
     592      if (isset($params[ 'address2' ]) && $params[ 'address2' ]) $post[ 'InvoiceHead.CustAddresLine2' ] = $params[ 'address2' ];
     593      if (isset($params[ 'city' ]) && $params[ 'city' ]) $post[ 'InvoiceHead.CustCity' ] = $params[ 'city' ];
     594    }
     595    if (!$this->param( 'doc_details' ) || in_array($this->param( 'doc_details' ), [ 'contact', 'full' ]) ) {
     596      if (isset($params[ 'phone' ]) && $params[ 'phone' ]) $post[ 'InvoiceHead.CustLinePH' ] = $params[ 'phone' ];
     597      if (isset($params[ 'mobile' ]) && $params[ 'mobile' ]) $post[ 'InvoiceHead.CustMobilePH' ] = $params[ 'mobile' ];
     598    }
     599
     600    if (isset($params[ 'tax_id' ]) && $params[ 'tax_id' ]) $post[ 'InvoiceHead.CompID' ] = $params[ 'tax_id' ];
     601    if (isset($params[ 'comment' ]) && $params[ 'comment' ]) $post[ 'InvoiceHead.Comments' ] = $params[ 'comment' ];
     602    if ($this->param( 'email_invoice' ) ) $post[ 'InvoiceHead.SendByEmail' ] = 'true';
     603    if ($this->param( 'vat_free' ) ) $post[ 'InvoiceHead.ExtIsVatFree' ] = 'true';
     604    if ($this->param( 'auto_create_account' ) ) $post[ 'InvoiceHead.IsAutoCreateUpdateAccount' ] = 'true';
     605    if ($this->param( 'auto_load_account' ) ) $post[ 'InvoiceHead.IsLoadInfoFromAccountID' ] = 'true';
     606    if ($this->param( 'department_id' ) ) $post[ 'InvoiceHead.DepartmentId' ] = $this->param( 'department_id' );
     607    //if ( isset($params[ 'payment_id' ]) && $params[ 'payment_id' ]) $post[ 'InvoiceHead.SiteUniqueId' ] = $params[ 'payment_id' ];
    608608
    609609    if ( isset( $params[ 'products' ] ) && is_array( $params[ 'products' ] ) ) {
     
    615615        $post[ 'InvoiceLines' . $index . '.Quantity' ] = $product[ 'qty' ];
    616616        $post[ 'InvoiceLines' . $index . '.IsPriceIncludeVAT' ] = 'true'; // Must be true - API requirement
    617         // TODO: support per item: $post['InvoiceLines1.IsVatFree'] = 'true';
     617        // TODO: support per item: $post[ 'InvoiceLines1.IsVatFree' ] = 'true';
    618618        if ( isset( $product[ 'id' ] ) && $product[ 'id' ] ) $post[ 'InvoiceLines' . $index . '.ProductID' ] = $product[ 'id' ];
    619619        $index++;
    620620      }
    621621    } else {
    622       $post[ 'InvoiceLines1.Description'] = $params['product'];
    623       $post[ 'InvoiceLines1.Price'] = $params['amount'];
    624       $post[ 'InvoiceLines1.Quantity'] = 1;
    625       $post[ 'InvoiceLines1.IsPriceIncludeVAT'] = 'true'; // Must be true - API requirement
    626       // TODO: support per item: $post['InvoiceLines1.IsVatFree'] = 'true';
     622      $post[ 'InvoiceLines1.Description' ] = $params[ 'product' ];
     623      $post[ 'InvoiceLines1.Price' ] = $params[ 'amount' ];
     624      $post[ 'InvoiceLines1.Quantity' ] = 1;
     625      $post[ 'InvoiceLines1.IsPriceIncludeVAT' ] = 'true'; // Must be true - API requirement
     626      // TODO: support per item: $post[ 'InvoiceLines1.IsVatFree' ] = 'true';
    627627      if ( isset( $params[ 'id' ] ) && $params[ 'id' ] ) $post[ 'InvoiceLines1.ProductID' ] = $params[ 'id' ];
    628628    }
     
    652652    return($post);
    653653  }
     654
     655//https://asmachta.co.il/?engine=Cardcom&payment_id=127046&redirect_url=https%3A%2F%2Fasmachta.co.il%2F%25d7%25a0%25d7%25a1%25d7%2597-%25d7%2598%25d7%2590%25d7%2591%25d7%2595%2F%3Fgf_simplepayment_return%3DaWRzPTJ8MTM0Nzk0Jmhhc2g9YWRkYmFjYmZiZGRjNDdlMTlkY2E1NzBiYjA0NmZkNzk&terminalnumber=125527&lowprofilecode=83fccd5d-6aed-4235-a1ab-62aceb769fad&ResponeCode=0&Operation=1&ResponseCode=0&Status=0
     656  // Sanitize url for Cardcom, so we wont send cardcom parameters
     657  public function url( $type, $params = null ) {
     658    if ( $url = parent::url( $type, $params ) ) {
     659      $parts = parse_url( $url );
     660      if ( isset( $parts[ 'query' ] ) ) {
     661        parse_str( $parts[ 'query' ], $query );
     662        foreach ( [ 'terminalnumber', 'lowprofilecode', 'ResponeCode', 'Operation', 'ResponseCode', 'Status', 'DealRespone', 'InvoiceResponseCode', 'OperationResponse', 'OperationResponseText', 'ReturnValue' ] as $param ) {
     663          unset( $query[ $param ] );
     664        }
     665        $parts[ 'query' ] = http_build_query( $query );
     666        $url = $parts[ 'scheme' ] . '://' . $parts[ 'host' ];
     667        if ( isset( $parts[ 'port' ]) ) {
     668          $url .= ':' . $parts[ 'port' ];
     669        }
     670        if ( isset( $parts[ 'path' ] ) ) {
     671          $url .= $parts[ 'path' ];
     672        }
     673        if ( $parts[ 'query' ] ) {
     674          $url .= '?' . $parts[ 'query' ];
     675        }
     676        if ( isset( $parts[ 'fragment' ] ) ) {
     677          $url .= '#' . $parts[ 'fragment' ];
     678        }
     679      }
     680    }
     681    return( $url );
     682  }
    654683 
    655684}
  • simple-payment/trunk/vendor/yalla-ya/simple-payment/Engines/Engine.php

    r3318371 r3319619  
    137137    public function url( $type, $params = null ) {
    138138      $url = $this->callback;
    139       $qry = [];
     139      $qry = [
     140        'op' => $type,
     141        'engine' => static::$name
     142      ];
    140143      if ( strpos( $url, 'transaction_id' ) === false ) $qry[ 'transaction_id' ] = $this->transaction;
    141144      if ( isset( $params[ 'payments' ] ) && strpos( $url, 'payments' ) === false ) $qry[ 'payments' ] = $params[ 'payments' ];
     
    143146      if ( isset( $params[ 'target' ] ) && strpos( $url, 'target' ) === false ) $qry[ 'target' ] = $params[ 'target' ];
    144147      if ( isset( $params[ 'redirect_url' ] ) && strpos( $url, 'redirect_url' ) === false ) $qry[ 'redirect_url' ] = $params[ 'redirect_url' ];
    145       return( $url . ( strpos( $url, '?' ) ? '&' : '?' ) . 'op=' . $type . '&engine=' . static::$name . ( $qry ? '&' . http_build_query( $qry ) : '' ) );
     148      return( $url . ( strpos( $url, '?' ) ? '&' : '?' ) . ( $qry ? '&' . http_build_query( $qry ) : '' ) );
    146149    }
    147150
Note: See TracChangeset for help on using the changeset viewer.