function criar_filtro() { $hbox = $this->add_button('id', $id = new TInteger()); $id->set_filter('CodConta', 'Tb_Del_Contas_Pagar.Cod_S_Conta', 'Cod. Conta:'); $this->add_button('filial', new TFiliais(null), $hbox); $hbox = $this->add_button('fornec', $fornec = new TString()); $fornec->set_filter('Fornecedor', 'Tb_Fornecedores.Nome', ' Fornecedor: '); $this->add_button('ndoc', $ndoc = new TString(), $hbox); $ndoc->set_filter('NumDoc', 'NumDoc', ' Num. do Doc.: '); $hbox = $this->add_button('valor_doc', $valor_doc = new TFloat()); $valor_doc->set_filter('ValorDoc', 'ValorDoc', ' Valor do Doc.: '); $this->add_button('parc', $parc = new TInteger(), $hbox); $parc->set_filter('Parcela', 'Parcela', 'Parcela', ' Parcela: '); $this->add_button('venc', $venc = new TData(), $hbox); $venc->set_filter('Vencimento', 'Vencimento', ' Vencimento: '); $this->add_button('cancel', $cancel = new TData(), $hbox); $cancel->set_filter('Cancelado', 'Tb_Del_Contas_Pagar.DataInc', ' Cancelamento: '); }
function criar_filtro() { $hbox = $this->add_button('id', $id = new TInteger()); $id->set_filter('Id', 'Tb_Contas_Pagar.Cod_S_Conta', ' Id.: '); $this->add_button('filial', new TFiliais(null), $hbox); $this->add_button('tipo', new TTipoDoc(null), $hbox); $hbox = $this->add_button('fornec', $fornec = new TString()); $fornec->set_filter('Fornecedor', 'Tb_Fornecedores.Nome', ' Fornecedor: ', ''); $this->add_button('ndoc', $ndoc = new TString(), $hbox); $ndoc->set_filter('NumDoc', 'NumDoc', ' Num. do Doc.: '); $hbox = $this->add_button('valor_doc', $valor_doc = new TFloat()); $valor_doc->set_filter('ValorDoc', 'ValorDoc', ' Valor do Doc.: '); $this->add_button('n_parc', $n_parc = new TInteger(), $hbox); $n_parc->set_filter('Parcela', 'Parcela', ' Parcela: '); $this->add_button('dat_emi', $dat_emi = new TData(), $hbox); $dat_emi->set_filter('Emissao', 'Tb_Contas_Pagar.DataInc', latin1(' Emissão: ')); $this->add_button('dat_venc', $dat_venc = new TData(), $hbox); $dat_venc->set_filter('Vencimento', 'Tb_Contas_Pagar.Vencimento', ' Vencimento: '); }
function criar_filtro() { $hbox = $this->add_button('id', $id = new TInteger()); $id->set_filter('CodConta', 'Tb_Mov_Contas_Pagar.Cod_S_Conta', 'Cod. Conta:'); $this->add_button('filial', new TFiliais(null), $hbox); $this->add_button('banco', new TBancos(null), $hbox); $hbox = $this->add_button('fornec', $fornec = new TString()); $fornec->set_filter('Fornecedor', 'Tb_Fornecedores.Nome', ' Fornecedor: '); $this->add_button('ndoc', $ndoc = new TString(), $hbox); $ndoc->set_filter('NumDoc', 'NumDoc', ' Num. do Doc.: '); $this->add_button('dia_pgto', $dia_pgto = new TData(), $hbox); $dia_pgto->set_filter('Pagamento', 'Tb_Mov_Contas_Pagar.DataInc', ' Data Pgto: '); $hbox = $this->add_button('tipo_desp', new TTipoDespesa(null)); $this->add_button('form_pgto', new TFormaPgto(null), $hbox); $hbox = $this->add_button('juros', $juros = new TFloat()); $juros->set_filter('Juros', 'Juros', ' Juros: '); $this->add_button('desc', $desc = new TFloat(), $hbox); $desc->set_filter('Desconto', 'Desconto', ' Desconto: '); $this->add_button('total', $total = new TFloat(), $hbox); $total->set_filter('Total', 'Total', ' Valor Pago: '); }
/** * Tests the Stripe Subscription gateway * @test */ function stripeplan_subscription() { $gateway = MS_Model_Gateway::factory(MS_Gateway_Stripeplan::ID); $user_id = TData::id('user', 'editor'); $membership_id = TData::id('membership', 'recurring'); $subscription = TData::subscribe($user_id, $membership_id); $controller = MS_Factory::load('MS_Controller_Gateway'); $gateway->update_stripe_data(); $data = array('card' => array('number' => '4242424242424242', 'exp_month' => 12, 'exp_year' => date('Y') + 1, 'cvc' => '314')); $res = M2_Stripe_Token::create($data); $token = $res->id; $form_data = array('_wpnonce' => wp_create_nonce($gateway->id . '_' . $subscription->id), 'gateway' => $gateway->id, 'ms_relationship_id' => $subscription->id, 'step' => 'process_purchase', 'stripeToken' => $token, 'stripeTokenType' => 'card', 'stripeEmail' => '*****@*****.**'); $_POST = $form_data; $_REQUEST = $_POST; // Right now the subscription must have status PENDING $this->assertEquals(MS_Model_Relationship::STATUS_PENDING, $subscription->status); /* * This function processes the purchase and will set the subscription * to active. */ $controller->process_purchase(); // Check the subscription status. $this->assertEquals(MS_Model_Relationship::STATUS_ACTIVE, $subscription->status); $this->assertEquals(1, count($subscription->payments)); // Modify the expiration date to trigger another payment. $today = date('Y-m-d'); $subscription->expire_date = $today; $this->assertEquals($today, $subscription->expire_date); $this->assertEquals(0, $subscription->get_remaining_period()); // Trigger next payment and validate it. $subscription->check_membership_status(); $this->assertEquals(2, count($subscription->payments)); // Modify the expiration date to trigger another payment. $subscription->expire_date = $today; $this->assertEquals($today, $subscription->expire_date); $this->assertEquals(0, $subscription->get_remaining_period()); // Trigger next payment and validate it. // THIS TIME NO PAYMENT SHOULD BE MADE because paycycle_repetitions = 2! $subscription->check_membership_status(); $this->assertEquals(2, count($subscription->payments)); // Also the subscription should be cancelled at stripe now. $customer_id = $subscription->get_member()->get_gateway_profile(MS_Gateway_Stripe_Api::ID, 'customer_id'); $customer = M2_Stripe_Customer::retrieve($customer_id); $invoice = $subscription->get_previous_invoice(); $stripe_sub_id = $invoice->external_id; $stripe_sub = $customer->subscriptions->retrieve($stripe_sub_id); $this->assertEquals('active', $stripe_sub->status); $this->assertTrue($stripe_sub->cancel_at_period_end); // Clean up. $customer->delete(); }
/** * Checks if shared-setup was working. * @test */ function staging_data_is_correct() { $this->assertFalse(empty(TData::id('user', 'admin'))); wp_set_current_user(TData::id('user', 'admin')); $this->assertEquals(get_current_user_id(), TData::id('user', 'admin')); $this->assertFalse(empty(TData::id('user', 'editor'))); $this->assertFalse(empty(TData::id('post', 'sample-page'))); $this->assertEquals('page', get_post_type(TData::id('post', 'sample-page'))); $ms_id = TData::id('membership', 'simple'); $this->assertFalse(empty($ms_id)); $membership = MS_Factory::load('MS_Model_Membership', $ms_id); $this->assertEquals($ms_id, $membership->id); $this->assertEquals(29, $membership->price); }
/** * Check member capability add-on. * @test */ function member_capabilities_rule() { // We only test the addon as an isolated unit. $addon = MS_Factory::load('MS_Rule_MemberCaps_Model'); remove_all_filters('user_has_cap'); $addon->protect_admin_content(); wp_set_current_user(TData::id('user', 'admin')); $this->assertTrue(current_user_can('manage_options'), 'admin'); $this->assertTrue(current_user_can('edit_theme_options'), 'admin'); wp_set_current_user(TData::id('user', 'editor')); $this->assertFalse(current_user_can('manage_options'), 'editor'); $this->assertFalse(current_user_can('edit_theme_options'), 'editor'); $this->assertTrue(current_user_can('edit_pages'), 'editor'); $this->assertTrue(current_user_can('delete_pages'), 'editor'); }
/** * Resets the database. * * @since 1.0.0 */ public static function reset() { global $wpdb; // wipe all existing data. $wpdb->query("TRUNCATE TABLE {$wpdb->users};"); $wpdb->query("TRUNCATE TABLE {$wpdb->usermeta};"); $wpdb->query("TRUNCATE TABLE {$wpdb->posts};"); $wpdb->query("TRUNCATE TABLE {$wpdb->postmeta};"); $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '%transient_%';"); $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE 'MS_%';"); self::$ids = array('user' => array(), 'post' => array(), 'membership' => array()); // create demo users $users = array('admin' => array('role' => 'administrator'), 'editor' => array('role' => 'editor')); foreach ($users as $login => $data) { $defaults = array('user_login' => $login, 'user_pass' => $login . '-password', 'user_email' => $login . '@local.dev', 'role' => 'subscriber', 'user_nicename' => '', 'user_url' => '', 'display_name' => 'User ' . $login, 'nickname' => '', 'first_name' => '', 'last_name' => '', 'description' => '', 'user_registered' => ''); $data = shortcode_atts($defaults, $data); $id = wp_insert_user($data); if (!empty($data['meta'])) { foreach ($data['meta'] as $key => $val) { $val = maybe_serialize($val); update_user_meta($id, $key, $val); } } self::$ids['user'][$login] = $id; } // create demo posts $posts = array('sample-post' => array('post_content' => 'Just a very simple sample post...'), 'sample-page' => array('post_type' => 'page', 'post_content' => 'Just a very simple sample page...')); foreach ($posts as $slug => $data) { $defaults = array('post_type' => 'post', 'post_author' => self::id('user', 'admin'), 'post_title' => $slug, 'post_name' => $slug); $data = shortcode_atts($defaults, $data); $id = wp_insert_post($data); if (!empty($data['meta'])) { foreach ($data['meta'] as $key => $val) { $val = maybe_serialize($val); update_post_meta($id, $key, $val); } } self::$ids['post'][$slug] = $id; } // create demo memberships $memberships = array('simple' => array('name' => 'Simple Membership', 'type' => MS_Model_Membership::TYPE_STANDARD, 'payment_type' => MS_Model_Membership::PAYMENT_TYPE_PERMANENT, 'price' => 29, 'rule_values' => array()), 'simple-free' => array('name' => 'Simple Membership', 'type' => MS_Model_Membership::TYPE_STANDARD, 'payment_type' => MS_Model_Membership::PAYMENT_TYPE_PERMANENT, 'is_free' => true, 'price' => 0, 'rule_values' => array()), 'simple-trial' => array('name' => 'Simple Membership with Trial', 'type' => MS_Model_Membership::TYPE_STANDARD, 'payment_type' => MS_Model_Membership::PAYMENT_TYPE_PERMANENT, 'price' => 29, 'rule_values' => array(), 'trial_period_enabled' => true, 'trial_period' => array('period_unit' => 14, 'period_type' => 'days')), 'limited' => array('name' => 'Limited Membership', 'type' => MS_Model_Membership::TYPE_STANDARD, 'payment_type' => MS_Model_Membership::PAYMENT_TYPE_FINITE, 'price' => 19, 'rule_values' => array(), 'period' => array('period_unit' => 28, 'period_type' => 'days')), 'limited-trial' => array('name' => 'Limited Membership with Trial', 'type' => MS_Model_Membership::TYPE_STANDARD, 'payment_type' => MS_Model_Membership::PAYMENT_TYPE_FINITE, 'price' => 19, 'rule_values' => array(), 'period' => array('period_unit' => 28, 'period_type' => 'days'), 'trial_period_enabled' => true, 'trial_period' => array('period_unit' => 14, 'period_type' => 'days')), 'daterange-trial' => array('name' => 'Date-Range Membership with Trial', 'type' => MS_Model_Membership::TYPE_STANDARD, 'payment_type' => MS_Model_Membership::PAYMENT_TYPE_DATE_RANGE, 'price' => 39, 'rule_values' => array(), 'period_date_start' => date('Y-m-d', time() + self::ONE_DAY), 'period_date_end' => date('Y-m-d', time() + 10 * self::ONE_DAY), 'trial_period_enabled' => true, 'trial_period' => array('period_unit' => 14, 'period_type' => 'days')), 'free-limited' => array('name' => 'Free Limited Membership', 'type' => MS_Model_Membership::TYPE_STANDARD, 'payment_type' => MS_Model_Membership::PAYMENT_TYPE_FINITE, 'is_free' => true, 'price' => 0, 'rule_values' => array(), 'period' => array('period_unit' => 28, 'period_type' => 'days')), 'recurring' => array('name' => 'Unit-Test Recurring', 'type' => MS_Model_Membership::TYPE_STANDARD, 'payment_type' => MS_Model_Membership::PAYMENT_TYPE_RECURRING, 'is_free' => false, 'price' => 4, 'rule_values' => array(), 'pay_cycle_period' => array('period_unit' => 7, 'period_type' => 'days'), 'pay_cycle_repetitions' => 2)); foreach ($memberships as $key => $data) { $item = new MS_Model_Membership(); foreach ($data as $prop => $val) { if (!property_exists($item, $prop)) { continue; } $item->{$prop} = $val; } $item->save(); $id = $item->id; self::$ids['membership'][$key] = $id; } // Prepare Payment Gateways. $gateway = MS_Model_Gateway::factory(MS_Gateway_Stripe::ID); $gateway->mode = MS_Gateway::MODE_SANDBOX; $gateway->active = true; $gateway->test_secret_key = 'sk_test_MSKvYHhIm3kKNr4tshnZHIEk'; $gateway->test_publishable_key = 'pk_test_h8fk0CAW287ToA3o6aeehThB'; $gateway->save(); $gateway = MS_Model_Gateway::factory(MS_Gateway_Stripeplan::ID); $gateway->mode = MS_Gateway::MODE_SANDBOX; $gateway->active = true; $gateway->test_secret_key = 'sk_test_MSKvYHhIm3kKNr4tshnZHIEk'; $gateway->test_publishable_key = 'pk_test_h8fk0CAW287ToA3o6aeehThB'; $gateway->save(); // Clear the plugin Factory-Cache MS_Factory::_reset(); }
/** * Test changing the membership payment plan from permanent to recurring. * @test */ function permanent_to_recurring() { $user_id = TData::id('user', 'editor'); $membership_id = TData::id('membership', 'simple'); $subscription = TData::subscribe($user_id, $membership_id); $invoice = $subscription->get_current_invoice(); $invoice->pay_it('stripe', 'external_123'); // Now we have a user that is subscribed to a permanent membership. $start_date = MS_Helper_Period::current_date(); $this->assertEquals($start_date, $subscription->start_date); $this->assertEquals('', $subscription->expire_date); $this->assertTrue($invoice->is_paid()); $this->assertEquals('active', $subscription->status); // This check should not modify the subscription. $subscription->check_membership_status(); $this->assertEquals($start_date, $subscription->start_date); $this->assertEquals('', $subscription->expire_date); $this->assertTrue($invoice->is_paid()); $this->assertEquals('active', $subscription->status); // Now the user changes the membership to recurring. $membership = $subscription->get_membership(); $membership->payment_type = MS_Model_Membership::PAYMENT_TYPE_RECURRING; $membership->pay_cycle_period_unit = 7; $membership->pay_cycle_period_type = 'days'; $membership->save(); $this->assertEquals(MS_Model_Membership::PAYMENT_TYPE_RECURRING, $membership->payment_type); // The membership status check is automaticaly done every six hours. // It will update the subscription details to match the new payment type. $subscription->check_membership_status(); // Confirm that the existing subscription has a correct expire date. $expire_date = MS_Helper_Period::add_interval(7, 'days', $start_date); $this->assertEquals($expire_date, $subscription->expire_date); }