Ejemplo n.º 1
0
$wpdb->query($sql);
// transaction options, custom fields : mgm_transaction_options
$sql = "CREATE TABLE IF NOT EXISTS `" . TBL_MGM_TRANSACTION_OPTION . "` (\r\r\n\t\t`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,\r\r\n\t\t`transaction_id` bigint(20) UNSIGNED NOT NULL,\t\t\t\r\r\n\t\t`option_name` VARCHAR( 255 ) NOT NULL ,\r\r\n\t\t`option_value` TEXT NOT NULL,\r\r\n\t\t UNIQUE KEY `transaction_id` (`transaction_id`,`option_name`)\r\r\n\t\t) {$charset_collate} COMMENT = 'transaction options'";
$wpdb->query($sql);
// protected urls : mgm_post_protected_urls
$sql = "CREATE TABLE IF NOT EXISTS `" . TBL_MGM_POST_PROTECTED_URL . "` (\r\r\n\t\t`id` BIGINT(20) UNSIGNED AUTO_INCREMENT,\r\r\n\t\t`url` VARCHAR(255) NOT NULL,\r\r\n\t\t`post_id` BIGINT(20) UNSIGNED NULL,\r\r\n\t\t`membership_types` TEXT NULL,\t\t\r\r\n\t\tPRIMARY KEY (`id`)\r\r\n\t\t) {$charset_collate} COMMENT = 'protected post url'";
$wpdb->query($sql);
// rest api keys : mgm_rest_api_keys
$sql = "CREATE TABLE IF NOT EXISTS `" . TBL_MGM_REST_API_KEY . "` (\r\r\n\t\t`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,\r\r\n\t\t`api_key` varchar(40) NOT NULL,\r\r\n\t\t`level` smallint(5) UNSIGNED NOT NULL,\t\t\r\r\n\t\t`create_dt` DATETIME NOT NULL,\r\r\n\t\tPRIMARY KEY (`id`)\r\r\n\t\t) {$charset_collate} COMMENT = 'rest api keys'";
$wpdb->query($sql);
// rest api levels : mgm_rest_api_levels
$sql = "CREATE TABLE IF NOT EXISTS `" . TBL_MGM_REST_API_LEVEL . "` (\r\r\n\t\t`id` smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT,\r\r\n\t\t`level` smallint(5) UNSIGNED NOT NULL,\r\r\n\t\t`name` varchar(100) NOT NULL,\r\r\n\t\t`permissions` text NOT NULL,\r\r\n\t\t`limits` int(11) UNSIGNED NULL,\r\r\n\t\tPRIMARY KEY (`id`)\r\r\n\t\t) {$charset_collate} COMMENT = 'rest api access levels'";
$wpdb->query($sql);
// rest api logs : mgm_rest_api_logs
$sql = "CREATE TABLE IF NOT EXISTS `" . TBL_MGM_REST_API_LOG . "` (\r\r\n\t\t`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,\r\r\n\t\t`api_key` varchar(40) NOT NULL,\r\r\n\t\t`uri` varchar(255) NOT NULL,\r\r\n\t\t`method` varchar(6) NOT NULL,\r\r\n\t\t`params` text NOT NULL,\t\t\r\r\n\t\t`ip_address` varchar(15) NOT NULL,\t\t\r\r\n\t\t`is_authorized` enum('Y','N') NOT NULL,\r\r\n\t\t`create_dt` DATETIME NOT NULL,\r\r\n\t\tPRIMARY KEY (`id`)\r\r\n\t\t) {$charset_collate} COMMENT = 'rest api logs'";
$wpdb->query($sql);
// login logs : multiple_login_records
$sql = "CREATE TABLE IF NOT EXISTS `" . TBL_MGM_MULTIPLE_LOGIN_RECORDS . "` (\r\r\n\t  \t`id` bigint(20) NOT NULL AUTO_INCREMENT,\r\r\n\t  \t`user_id` bigint(20) DEFAULT NULL,\r\r\n\t  \t`pack_id` int(11) DEFAULT NULL,\r\r\n\t  \t`ip_address` varchar(30) NOT NULL,\r\r\n\t  \t`login_at` datetime,\r\r\n\t  \t`logout_at` datetime NULL DEFAULT NULL,\t  \t\r\r\n\t  \tPRIMARY KEY (`id`)\r\r\n\t) {$charset_collate} COMMENT = 'multiple login records'";
$wpdb->query($sql);
// ---------------------------------------------- country data ---------------------------------------------------------
// insert countries
$sql = "INSERT IGNORE INTO `" . TBL_MGM_COUNTRY . "` (`id`, `name`, `code`) VALUES \r\r\n\t\t(1, 'Asia/Pacific Region', 'AP'), (2, 'Europe', 'EU'), (3, 'Andorra', 'AD'), \r\r\n\t\t(4, 'United Arab Emirates', 'AE'), (5, 'Afghanistan', 'AF'), (6, 'Antigua and Barbuda', 'AG'), \r\r\n\t\t(7, 'Anguilla', 'AI'), (8, 'Albania', 'AL'), (9, 'Armenia', 'AM'), (10, 'Netherlands Antilles', 'AN'), (11, 'Angola', 'AO'),\r\r\n\t\t(12, 'Antarctica', 'AQ'), (13, 'Argentina', 'AR'), (14, 'American Samoa', 'AS'), (15, 'Austria', 'AT'), \r\r\n\t\t(16, 'Australia', 'AU'), (17, 'Aruba', 'AW'), (18, 'Azerbaijan', 'AZ'), (19, 'Bosnia and Herzegovina', 'BA'), \r\r\n\t\t(20, 'Barbados', 'BB'), (21, 'Bangladesh', 'BD'), (22, 'Belgium', 'BE'), (23, 'Burkina Faso', 'BF'), \r\r\n\t\t(24, 'Bulgaria', 'BG'), (25, 'Bahrain', 'BH'), (26, 'Burundi', 'BI'), (27, 'Benin', 'BJ'), (28, 'Bermuda', 'BM'), \r\r\n\t\t(29, 'Brunei Darussalam', 'BN'), (30, 'Bolivia', 'BO'), (31, 'Brazil', 'BR'), (32, 'Bahamas', 'BS'), (33, 'Bhutan', 'BT'), \r\r\n\t\t(34, 'Bouvet Island', 'BV'), (35, 'Botswana', 'BW'), (36, 'Belarus', 'BY'), (37, 'Belize', 'BZ'), (38, 'Canada', 'CA'), \r\r\n\t\t(39, 'Cocos (Keeling) Islands', 'CC'), (40, 'Congo, The Democratic Republic of the', 'CD'), (41, 'Central African Republic', 'CF'), \r\r\n\t\t(42, 'Congo', 'CG'), (43, 'Switzerland', 'CH'), (44, 'Cote D\\'Ivoire', 'CI'), (45, 'Cook Islands', 'CK'), \r\r\n\t\t(46, 'Chile', 'CL'), (47, 'Cameroon', 'CM'), (48, 'China', 'CN'), (49, 'Colombia', 'CO'), (50, 'Costa Rica', 'CR'), \r\r\n\t\t(51, 'Cuba', 'CU'), (52, 'Cape Verde', 'CV'), (53, 'Christmas Island', 'CX'), (54, 'Cyprus', 'CY'), \r\r\n\t\t(55, 'Czech Republic', 'CZ'), (56, 'Germany', 'DE'), (57, 'Djibouti', 'DJ'), (58, 'Denmark', 'DK'), \r\r\n\t\t(59, 'Dominica', 'DM'), (60, 'Dominican Republic', 'DO'), (61, 'Algeria', 'DZ'), (62, 'Ecuador', 'EC'), \r\r\n\t\t(63, 'Estonia', 'EE'), (64, 'Egypt', 'EG'), (65, 'Western Sahara', 'EH'), (66, 'Eritrea', 'ER'), (67, 'Spain', 'ES'), \r\r\n\t\t(68, 'Ethiopia', 'ET'), (69, 'Finland', 'FI'), (70, 'Fiji', 'FJ'), (71, 'Falkland Islands (Malvinas)', 'FK'), \r\r\n\t\t(72, 'Micronesia, Federated States of', 'FM'), (73, 'Faroe Islands', 'FO'), (74, 'France', 'FR'), \r\r\n\t\t(75, 'France, Metropolitan', 'FX'), (76, 'Gabon', 'GA'), (77, 'United Kingdom', 'GB'), (78, 'Grenada', 'GD'), \r\r\n\t\t(79, 'Georgia', 'GE'), (80, 'French Guiana', 'GF'), (81, 'Ghana', 'GH'), (82, 'Gibraltar', 'GI'), (83, 'Greenland', 'GL'), \r\r\n\t\t(84, 'Gambia', 'GM'), (85, 'Guinea', 'GN'), (86, 'Guadeloupe', 'GP'), (87, 'Equatorial Guinea', 'GQ'), (88, 'Greece', 'GR'), \r\r\n\t\t(89, 'South Georgia and the South Sandwich Islands', 'GS'), (90, 'Guatemala', 'GT'), (91, 'Guam', 'GU'), (92, 'Guinea-Bissau', 'GW'), \r\r\n\t\t(93, 'Guyana', 'GY'), (94, 'Hong Kong', 'HK'), (95, 'Heard Island and McDonald Islands', 'HM'), (96, 'Honduras', 'HN'), (97, 'Croatia', 'HR'), \r\r\n\t\t(98, 'Haiti', 'HT'), (99, 'Hungary', 'HU'), (100, 'Indonesia', 'ID'), (101, 'Ireland', 'IE'), (102, 'Israel', 'IL'), (103, 'India', 'IN'), \r\r\n\t\t(104, 'British Indian Ocean Territory', 'IO'), (105, 'Iraq', 'IQ'), (106, 'Iran, Islamic Republic of', 'IR'), (107, 'Iceland', 'IS'), (108, 'Italy', 'IT'),\r\r\n\t\t(109, 'Jamaica', 'JM'), (110, 'Jordan', 'JO'), (111, 'Japan', 'JP'), (112, 'Kenya', 'KE'), (113, 'Kyrgyzstan', 'KG'), (114, 'Cambodia', 'KH'),\r\r\n\t\t(115, 'Kiribati', 'KI'), (116, 'Comoros', 'KM'), (117, 'Saint Kitts and Nevis', 'KN'), (118, 'Korea, Democratic People\\'s Republic of', 'KP'), \r\r\n\t\t(119, 'Korea, Republic of', 'KR'), (120, 'Kuwait', 'KW'), (121, 'Cayman Islands', 'KY'), (122, 'Kazakstan', 'KZ'),\r\r\n\t\t(123, 'Lao People\\'s Democratic Republic', 'LA'), (124, 'Lebanon', 'LB'), (125, 'Saint Lucia', 'LC'), (126, 'Liechtenstein', 'LI'), \r\r\n\t\t(127, 'Sri Lanka', 'LK'), (128, 'Liberia', 'LR'), (129, 'Lesotho', 'LS'), (130, 'Lithuania', 'LT'), (131, 'Luxembourg', 'LU'), \r\r\n\t\t(132, 'Latvia', 'LV'), (133, 'Libyan Arab Jamahiriya', 'LY'), (134, 'Morocco', 'MA'), (135, 'Monaco', 'MC'), \r\r\n\t\t(136, 'Moldova, Republic of', 'MD'), (137, 'Madagascar', 'MG'), (138, 'Marshall Islands', 'MH'), (139, 'Macedonia', 'MK'), \r\r\n\t\t(140, 'Mali', 'ML'), (141, 'Myanmar', 'MM'), (142, 'Mongolia', 'MN'), (143, 'Macau', 'MO'), (144, 'Northern Mariana Islands', 'MP'), \r\r\n\t\t(145, 'Martinique', 'MQ'), (146, 'Mauritania', 'MR'), (147, 'Montserrat', 'MS'), (148, 'Malta', 'MT'), (149, 'Mauritius', 'MU'), \r\r\n\t\t(150, 'Maldives', 'MV'), (151, 'Malawi', 'MW'), (152, 'Mexico', 'MX'), (153, 'Malaysia', 'MY'), (154, 'Mozambique', 'MZ'), \r\r\n\t\t(155, 'Namibia', 'NA'), (156, 'New Caledonia', 'NC'), (157, 'Niger', 'NE'), (158, 'Norfolk Island', 'NF'), (159, 'Nigeria', 'NG'), \r\r\n\t\t(160, 'Nicaragua', 'NI'), (161, 'Netherlands', 'NL'), \r\r\n\t\t(162, 'Norway', 'NO'), (163, 'Nepal', 'NP'), (164, 'Nauru', 'NR'), (165, 'Niue', 'NU'), (166, 'New Zealand', 'NZ'),\r\r\n\t\t(167, 'Oman', 'OM'), (168, 'Panama', 'PA'), (169, 'Peru', 'PE'), (170, 'French Polynesia', 'PF'), (171, 'Papua New Guinea', 'PG'), \r\r\n\t\t(172, 'Philippines', 'PH'), (173, 'Pakistan', 'PK'), (174, 'Poland', 'PL'), (175, 'Saint Pierre and Miquelon', 'PM'), \r\r\n\t\t(176, 'Pitcairn Islands', 'PN'), (177, 'Puerto Rico', 'PR'), (178, 'Palestinian Territory', 'PS'), (179, 'Portugal', 'PT'),\r\r\n\t\t(180, 'Palau', 'PW'), (181, 'Paraguay', 'PY'), (182, 'Qatar', 'QA'), (183, 'Reunion', 'RE'), (184, 'Romania', 'RO'),\r\r\n\t\t(185, 'Russian Federation', 'RU'), (186, 'Rwanda', 'RW'), (187, 'Saudi Arabia', 'SA'), (188, 'Solomon Islands', 'SB'), \r\r\n\t\t(189, 'Seychelles', 'SC'), (190, 'Sudan', 'SD'), (191, 'Sweden', 'SE'), (192, 'Singapore', 'SG'), (193, 'Saint Helena', 'SH'),\r\r\n\t\t(194, 'Slovenia', 'SI'), (195, 'Svalbard and Jan Mayen', 'SJ'), (196, 'Slovakia', 'SK'), (197, 'Sierra Leone', 'SL'), \r\r\n\t\t(198, 'San Marino', 'SM'), (199, 'Senegal', 'SN'), (200, 'Somalia', 'SO'), (201, 'Suriname', 'SR'), \r\r\n\t\t(202, 'Sao Tome and Principe', 'ST'), (203, 'El Salvador', 'SV'), (204, 'Syrian Arab Republic', 'SY'),\r\r\n\t\t(205, 'Swaziland', 'SZ'), (206, 'Turks and Caicos Islands', 'TC'), (207, 'Chad', 'TD'), (208, 'French Southern Territories', 'TF'), \r\r\n\t\t(209, 'Togo', 'TG'), (210, 'Thailand', 'TH'), (211, 'Tajikistan', 'TJ'), (212, 'Tokelau', 'TK'), (213, 'Turkmenistan', 'TM'),\r\r\n\t\t(214, 'Tunisia', 'TN'), (215, 'Tonga', 'TO'), (216, 'Timor-Leste', 'TL'), (217, 'Turkey', 'TR'), (218, 'Trinidad and Tobago', 'TT'),\r\r\n\t\t(219, 'Tuvalu', 'TV'), (220, 'Taiwan', 'TW'), (221, 'Tanzania, United Republic of', 'TZ'), (222, 'Ukraine', 'UA'), (223, 'Uganda', 'UG'), \r\r\n\t\t(224, 'United States Minor Outlying Islands', 'UM'), (225, 'United States', 'US'), (226, 'Uruguay', 'UY'), (227, 'Uzbekistan', 'UZ'),\r\r\n\t\t(228, 'Holy See (Vatican City State)', 'VA'), (229, 'Saint Vincent and the Grenadines', 'VC'), (230, 'Venezuela', 'VE'), \r\r\n\t\t(231, 'Virgin Islands, British', 'VG'), (232, 'Virgin Islands, U.S.', 'VI'), (233, 'Vietnam', 'VN'), (234, 'Vanuatu', 'VU'), \r\r\n\t\t(235, 'Wallis and Futuna', 'WF'), (236, 'Samoa', 'WS'), (237, 'Yemen', 'YE'), (238, 'Mayotte', 'YT'), (239, 'Serbia', 'RS'), \r\r\n\t\t(240, 'South Africa', 'ZA'), (241, 'Zambia', 'ZM'), (242, 'Montenegro', 'ME'), (243, 'Zimbabwe', 'ZW'), (244, 'Anonymous Proxy', 'A1'), \r\r\n\t\t(245, 'Satellite Provider', 'A2'), (246, 'Other', 'O1'), (247, 'Aland Islands', 'AX'), (248, 'Guernsey', 'GG'), (249, 'Isle of Man', 'IM'),\r\r\n\t\t(250, 'Jersey', 'JE'), (251, 'Saint Barthelemy', 'BL'), (252, 'Saint Martin', 'MF');";
$wpdb->query($sql);
// ---------------------------------------------- api default data ---------------------------------------------------------
// level
$sql = "INSERT IGNORE INTO `" . TBL_MGM_REST_API_LEVEL . "` (`id`, `level`, `name`, `permissions`, `limits`) VALUES \r\r\n\t\t (1, 1, 'full access', '[]', 1000);";
$wpdb->query($sql);
// keys
$sql = "INSERT IGNORE INTO `" . TBL_MGM_REST_API_KEY . "` (`id`, `api_key`, `level`, `create_dt`) VALUES \r\r\n\t\t (1, '" . mgm_create_token() . "', '1', NOW());";
$wpdb->query($sql);
// end of file
 function _get_button_data($pack, $tran_id = NULL)
 {
     // system setting
     $system_obj = mgm_get_class('system');
     $user_id = $pack['user_id'];
     // user email
     if (isset($pack['user_id'])) {
         $user_id = $pack['user_id'];
         $user = get_userdata($user_id);
         $user_email = $user->user_email;
     }
     // item
     $item = $this->get_pack_item($pack);
     //pack currency over rides genral setting currency - issue #1602
     if (!isset($pack['currency']) || empty($pack['currency'])) {
         $pack['currency'] = $this->setting['currency'];
     }
     // setup data array
     $data = array('PARTNER' => $this->setting['partner'], 'VENDOR' => $this->setting['vendor'], 'USER' => $this->setting['username'], 'PWD' => $this->setting['password'], 'CURRENCY' => $pack['currency'], 'TRXTYPE' => 'S', 'INVNUM' => $tran_id, 'AMT' => $pack['cost'], 'CREATESECURETOKEN' => 'Y', 'VERBOSITY' => 'HIGH', 'SECURETOKENID' => mgm_create_token('unique', 36), 'COMMENT1' => $this->_remove_special_chars($item['name']));
     // additional fields
     if (isset($user)) {
         // email
         if (isset($user_email) && !empty($user_email)) {
             $data['EMAIL'] = $user_email;
         }
         $this->_set_address_fields($user, $data);
     }
     // subscription purchase with ongoing/limited
     if (!isset($pack['buypost']) && isset($pack['duration_type'])) {
         // standard check
         //$data['BILLINGTYPE'] = 'RecurringBilling';// MerchantInitiatedBilling for BAID error as suggested by PayPal
         $data['L_BILLINGTYPE0'] = 'MerchantInitiatedBilling';
         $data['_TRAILER_PASSTHROUGH'] = 'Y';
     }
     // update currency - issue #1602
     /*		
     		if($pack['currency'] != $this->setting['currency']){
     			$pack['currency'] = $this->setting['currency'];
     		}*/
     // strip
     $data = mgm_stripslashes_deep($data);
     // add filter @todo test
     $data = apply_filters('mgm_payment_button_data', $data, $tran_id, $this->module, $pack);
     // update pack/transaction
     mgm_update_transaction(array('data' => json_encode($pack), 'module' => $this->module), $tran_id);
     // return data
     return $data;
 }
/**
 * get post purchase buttons
 * final step for post purchase
 *
 * @param void
 * @return $html
 */
function mgm_get_post_purchase_buttons()
{
    // get current user data - issue #1421
    $user = wp_get_current_user();
    // pack
    $pack = NULL;
    // addon options
    if ($addon_option_ids = mgm_post_var('addon_options')) {
        $addon_options = mgm_get_addon_options_only($addon_option_ids);
        // mgm_pr($addon_options);
    }
    // post purchase
    if (isset($_POST['post_id'])) {
        //issue #1250
        if (isset($_POST['mgm_postpurchase_field']['coupon']) && !empty($_POST['mgm_postpurchase_field']['coupon'])) {
            //issue #1250 - Coupon validation
            if (!empty($_POST['form_action'])) {
                // check if its a valid coupon
                if (!($coupon = mgm_get_coupon_data($_POST['mgm_postpurchase_field']['coupon']))) {
                    //redirect back to the form
                    $q_arg = array('error_field' => 'Coupon', 'error_type' => 'invalid', 'error_field_value' => $_POST['mgm_postpurchase_field']['coupon']);
                    $redirect = add_query_arg($q_arg, $_POST['form_action']);
                    mgm_redirect($redirect);
                    exit;
                }
            }
        }
        // post id
        $post_id = $_POST['post_id'];
        // gete mgm data
        $post_obj = mgm_get_post($post_id);
        $cost = mgm_convert_to_currency($post_obj->purchase_cost);
        $product = $post_obj->product;
        $allowed_modules = $post_obj->allowed_modules;
        // post data
        $post = get_post($post_id);
        $title = $post->post_title;
        // item name -issue #1380
        $item_name = apply_filters('mgm_post_purchase_itemname', sprintf(__('Purchase Post - %s', 'mgm'), $title));
        // set pack
        $pack = array('duration' => 1, 'item_name' => $item_name, 'buypost' => 1, 'cost' => $cost, 'title' => $title, 'product' => $product, 'post_id' => $post_id, 'allowed_modules' => $allowed_modules);
    } else {
        if (isset($_POST['postpack_id'])) {
            // post pack purchase
            //issue #1250
            if (isset($_POST['mgm_postpurchase_field']['coupon']) && !empty($_POST['mgm_postpurchase_field']['coupon'])) {
                //issue #1250 - Coupon validation
                if (!empty($_POST['form_action'])) {
                    // check if its a valid coupon
                    if (!($coupon = mgm_get_coupon_data($_POST['mgm_postpurchase_field']['coupon']))) {
                        //redirect back to the form
                        $q_arg = array('error_field' => 'Coupon', 'error_type' => 'invalid', 'error_field_value' => $_POST['mgm_postpurchase_field']['coupon']);
                        $redirect = add_query_arg($q_arg, $_POST['form_action']);
                        mgm_redirect($redirect);
                        exit;
                    }
                }
            }
            // post pack purchase
            $postpack_id = $_POST['postpack_id'];
            // pcak id
            $postpack_post_id = $_POST['postpack_post_id'];
            // post id where pack is listed, redirect here
            // get pack
            $postpack = mgm_get_postpack($postpack_id);
            $cost = mgm_convert_to_currency($postpack->cost);
            $product = json_decode($postpack->product, true);
            $modules = json_decode($postpack->modules, true);
            //mgm_pr($postpack);
            // item name -issue #1380
            $item_name = apply_filters('mgm_postpack_purchase_itemname', sprintf(__('Purchase Post Pack - %s', 'mgm'), $postpack->name));
            // post id
            $post_id = mgm_get_postpack_posts_csv($postpack_id);
            // set pack
            $pack = array('duration' => 1, 'item_name' => $item_name, 'buypost' => 1, 'cost' => $cost, 'title' => $postpack->name, 'product' => $product, 'post_id' => $post_id, 'postpack_id' => $postpack_id, 'postpack_post_id' => $postpack_post_id, 'allowed_modules' => $modules);
        }
    }
    // check
    if (!$pack) {
        return __('Error in Payment! No data available ');
        exit;
    }
    // guest token	-issue #1421
    if (isset($_POST['guest_purchase']) && $_POST['guest_purchase'] == TRUE && $user->ID <= 0) {
        $pack['guest_token'] = sanitize_title_for_query(mgm_create_token());
    }
    // addon options
    if (isset($addon_options) && !empty($addon_options)) {
        $pack['addon_options'] = $addon_options;
    }
    // get coupon
    $post_purchase_coupon = mgm_save_partial_fields(array('on_postpurchase' => true), 'mgm_postpurchase_field', $pack['cost'], false, 'postpurchase');
    // alter
    mgm_get_post_purchase_coupon_pack($post_purchase_coupon, $pack);
    // Eg: $_POST['mgm_payment_gateways'] = mgm_paypal
    $cf_payment_gateways = isset($_POST['mgm_payment_gateways']) && !empty($_POST['mgm_payment_gateways']) ? $_POST['mgm_payment_gateways'] : null;
    // bypass step2 if payment gateway is submitted: issue #: 469
    if (!is_null($cf_payment_gateways)) {
        // get pack
        // mgm_get_upgrade_coupon_pack($member, $selected_pack);
        // cost
        if ((double) $pack['cost'] > 0) {
            //get an object of the payment gateway:
            $mod_obj = mgm_get_module($cf_payment_gateways, 'payment');
            // tran options
            $tran_options = array('user_id' => $user->ID);
            // is register & purchase
            if (isset($_POST['post_id'])) {
                $tran_options['post_id'] = (int) $_POST['post_id'];
            }
            // postpack id
            if (isset($_POST['postpack_id'])) {
                $tran_options['postpack_id'] = (int) $_POST['postpack_id'];
            }
            // is register & purchase postpack
            if (isset($_POST['postpack_post_id']) && isset($_POST['postpack_id'])) {
                $tran_options['postpack_post_id'] = (int) $_POST['postpack_post_id'];
                $tran_options['postpack_id'] = (int) $_POST['postpack_id'];
            }
            // create transaction
            $tran_id = mgm_add_transaction($pack, $tran_options);
            // bypass directly to process return if manual payment:
            if ($cf_payment_gateways == 'mgm_manualpay') {
                // set
                $_POST['custom'] = $tran_id;
                // direct call to module return function:
                $mod_obj->process_return();
                // exit
                exit;
            }
            // encode id:
            $tran_id = mgm_encode_id($tran_id);
            $redirect = $mod_obj->_get_endpoint('html_redirect', true);
            $redirect = add_query_arg(array('tran_id' => $tran_id), $redirect);
            // redirect
            mgm_redirect($redirect);
            // this goes to subscribe, mgm_functions.php/mgm_get_subscription_buttons
            // exit
            exit;
        }
    }
    // get payment modules
    $a_payment_modules = mgm_get_class('system')->get_active_modules('payment');
    // init
    $payment_modules = array();
    // when active
    if ($a_payment_modules) {
        // loop
        foreach ($a_payment_modules as $payment_module) {
            // not trial
            if (in_array($payment_module, array('mgm_free', 'mgm_trial'))) {
                continue;
            }
            // store
            $payment_modules[] = $payment_module;
        }
    }
    // init
    $button = '';
    // transaction
    $tran_id = NULL;
    $button_printed = 0;
    // loop modules
    foreach ($payment_modules as $module) {
        // object
        $mod_obj = mgm_get_module($module, 'payment');
        // check buypost support
        if (in_array('buypost', $mod_obj->supported_buttons)) {
            // create transaction
            if (!$tran_id) {
                $tran_id = mgm_add_transaction($pack);
            }
            // button code
            if (isset($pack['allowed_modules'])) {
                // Issue #1562: If no payment module is selected, display all supported modules
                if (!empty($pack['allowed_modules']) && FALSE === in_array($module, $pack['allowed_modules'])) {
                    continue;
                }
            }
            $button_code = $mod_obj->get_button_buypost(array('pack' => $pack, 'tran_id' => $tran_id), true);
            $button_printed++;
            // get button
            $button .= "<div class='mgm_custom_filed_table'>" . $button_code . "</div>";
        }
    }
    // none active
    if ($button_printed == 0) {
        $button .= sprintf('<p class="mgm-no-module"> %s </p>', __('No Payment module active for this Content Purchase.', 'mgm'));
    }
    // if Cost is zero, then process using free module.: issue#: 883
    if ($tran_id && $pack['cost'] == 0 && in_array('mgm_free', $a_payment_modules) && mgm_get_module('mgm_free')->is_enabled()) {
        // module
        $module = 'mgm_free';
        // payments url
        $payments_url = mgm_get_custom_url('transactions');
        // query_args
        $query_args = array('method' => 'payment_return', 'module' => $module, 'custom' => $tran_id);
        // redirector
        if (isset($_REQUEST['redirector'])) {
            // set
            $query_args['redirector'] = $_REQUEST['redirector'];
        }
        // redirect to module to mark the payment as complete
        $redirect = add_query_arg($query_args, $payments_url);
        // redirect
        mgm_redirect($redirect);
    }
    // html
    $return = '<div class="post_purchase_select_gateway">' . __('Please Select a Payment Gateway.', 'mgm') . '</div>' . $button;
    // return
    return $return;
}
Ejemplo n.º 4
0
		    		<b><?php 
_e('Add Key', 'mgm');
?>
</b>
				</div>
			</div>
	  		<div class="row brBottom">
	    		<div class="cell width120px">
		    		<span class="required"><?php 
_e('API Key', 'mgm');
?>
</span>: 
				</div>
	    		<div class="cell textalignleft">
		    		<input type="text" name="api_key" size="40" maxlength="40" value="<?php 
echo mgm_create_token();
?>
"/>					
				</div>
			</div>
	  		<div class="row brBottom">
	    		<div class="cell width120px">
		    		<span class="required"><?php 
_e('Level', 'mgm');
?>
</span>: 
				</div>
	    		<div class="cell textalignleft">
		    		<select name="level" class="width50px">
						<?php 
echo mgm_make_combo_options($data['levels'], 1, MGM_VALUE_ONLY);