/** * Test that EDD sale of non-variable product is properly priced/recorded * * @since 1.1.0 * * @group pricez * @group edd_price * * @covers \ingot\testing\tests\price\plugins\edd */ public function testPriceTrackingNonVariableProduct() { $price_is = 10; $product = ingot_test_data_price::edd_create_simple_download($price_is); $group_id = \ingot\testing\crud\group::create(['type' => 'price', 'sub_type' => 'edd', 'meta' => ['product_ID' => $product->ID], 'wp_ID' => $product->ID], true); $variant_one = \ingot\testing\crud\variant::create(['group_ID' => $group_id, 'type' => 'price', 'meta' => ['price' => [0.5]], 'content' => $product->ID], true); $variant_two = \ingot\testing\crud\variant::create(['group_ID' => $group_id, 'type' => 'price', 'meta' => ['price' => [0.5]], 'content' => $product->ID], true); $group = \ingot\testing\crud\group::read($group_id); $group['variants'] = [$variant_one, $variant_two]; \ingot\testing\crud\group::update($group, $group_id, true); $cookie_class = new \ingot\testing\cookies\price([]); $price_cookie = $cookie_class->get_cookie(); $this->assertArrayHasKey('edd', $price_cookie); $this->assertFalse(empty($price_cookie['edd'])); $this->assertInternalType('array', $price_cookie['edd']); $product_id = \ingot\testing\utility\price::get_product_ID($group); $this->assertEquals($product_id, $product->ID); $this->assertArrayHasKey($product_id, $price_cookie['edd']); new \ingot\testing\tests\price\plugins\edd($price_cookie['edd']); $test = \ingot\testing\utility\price::get_price_test_from_cookie('edd', $product->ID, $price_cookie); $this->assertInternalType('object', $test); $price_should_be = $test->get_price(); //NOTE: USING edd_get_download_price here is to ensure we don't have recursion $this->assertEquals(edd_get_download_price($product->ID), $price_should_be); $group_obj = new \ingot\testing\object\group($group_id); $lever = $group_obj->get_lever($test->ID); $this->assertInternalType('object', $lever); $before_wins = $lever->getNumerator(); $payment_id = ingot_test_data_price::edd_create_simple_payment($product); edd_complete_purchase($payment_id, 'publish', 'pending'); $group_obj = new \ingot\testing\object\group($group_id); $lever = $group_obj->get_lever($test->ID); $this->assertInternalType('object', $lever); $after_wins = $lever->getNumerator(); $this->assertEquals($before_wins + 1, $after_wins); }
/** * Simple wrapper for the api call / response treatement * * @param string $url * @param array $fields */ private function performPayment($url, $fields) { $result = $this->curlAction($url, $fields); $result = $this->getDataTransaction($result); if ($result['CODEREPONSE'] == '00000') { edd_update_payment_status($this->payment, 'publish'); edd_complete_purchase($this->payment, 'publish', 'pending'); foreach ($this->purchaseDatas['downloads'] as $download) { $log = edd_record_log('Payment', 'Payment', $download['id'], 'sale'); update_post_meta($log, '_edd_log_payment_id', $this->payment); } edd_empty_cart(); edd_send_to_success_page(); } else { if ($result['CODEREPONSE'] == '00001' || $result['CODEREPONSE'] == '00003') { $settings = $this->getSettings(); // if the first prod url failed try the second if (!$settings['preprod'] && $url !== $settings['url_prod_2'] && isset($settings['url_prod_2'])) { $this->performPayment($settings['url_prod_2'], $fields); } edd_record_gateway_error(__('Payment Error', 'edd'), __('Payment gateways unavailable', 'edd')); edd_send_back_to_checkout('?payment-mode=' . $this->gateway); } else { edd_record_gateway_error(__('Payment Error', 'edd'), $result['COMMENTAIRE']); edd_send_back_to_checkout('?payment-mode=' . $this->gateway); } } }
/** * Track EDD sale conversions * * @since 1.1.0 * * @group group * @group destination * @group edd * * @covers \ingot\testing\tests\click\destination\hooks::edd_complete_purchase() * @covers \ingot\testing\tests\click\destination\hooks::add_hooks() */ public function testEDDConversionsSale() { if (ingot_is_edd_active()) { $this->assertTrue(\ingot\testing\tests\click\destination\types::allowed_destination_type('sale_edd')); $product = ingot_test_data_price::edd_create_simple_download(10); $data = ingot_test_desitnation::create('sale_edd'); $group_id = $data['group_ID']; $this->assertTrue(is_numeric($group_id)); $variants = $data['variants']; new \ingot\testing\bandit\content($group_id); $variant_id = \ingot\testing\tests\click\destination\init::get_test($group_id); $this->assertTrue(is_numeric($variant_id)); \ingot\testing\tests\click\destination\init::set_tracking(); $this->assertTrue(in_array(\ingot\testing\tests\click\destination\init::get_test($group_id), $variants)); $variant_id = \ingot\testing\tests\click\destination\init::get_test($group_id); $hooks = new \ingot\testing\tests\click\destination\hooks([$group_id]); $payment_id = ingot_test_data_price::edd_create_simple_payment($product); edd_complete_purchase($payment_id, 'publish', 'pending'); $group = \ingot\testing\crud\group::read($group_id); $totals = \ingot\testing\utility\group::get_total($group); $this->assertEquals(3, $totals['total']); $this->assertEquals(2, $totals['conversions']); } }