t('Receipting Allocation'), 'description' => t('Check that when payments are made that the allocation of the payments is correct.'), 'group' => t('e-Commerce'), ); } function setUp() { parent::setUp('ec_product', 'ec_anon', 'ctools', 'ec_checkout', 'ec_buynow', 'ec_receipt', 'ec_store', 'ec_common', 'ec_receipt_test_payment', 'ec_customer', 'ec_address', 'search', 'ctools', 'ec_charge', 'rules', 'views'); variable_set('ec_default_currency', 'USD'); } function testCorrectAllocation() { $account = $this->drupalCreateUser(); $address = array( 'uid' => $account->uid, 'firstname' => $this->randomName(20), 'lastname' => $this->randomName(20), 'street1' => $this->randomName(52), 'street2' => $this->randomName(52), 'zip' => drupal_substr($this->randomName(10), -10), 'city' => $this->randomName(20), 'state' => $this->randomName(20), 'country' => 'US', ); drupal_write_record('ec_address', $address); $product = array( 'type' => 'product', 'ptype' => 'generic', 'price' => '20.00', 'revision' => 1, ); $node = $this->drupalCreateNode($product); $product = clone $node; $product->qty = 1; $params = array( 'customer' => ec_customer_get_by_uid($account->uid), 'items' => array( $product->nid => $product, ), ); $txn = ec_checkout_create_transaction('ec_buynow', $params, $this); $this->assertEqual(($txn->gross - ($txn->balance + $txn->allocated)), 0, t('Transaction balances internally'), 'e-Commerce'); $erid = ec_receipt_build_receipt('transaction', $txn); $receipt = ec_receipt_load($erid); $alloc[] = array( 'type' => 'transaction', 'id' => $txn->txnid, 'amount' => $txn->gross, ); ec_receipt_allocate($receipt, $alloc); $txn = ec_store_transaction_load($txn->txnid); $receipt = ec_receipt_load($erid); $this->assertEqual(($txn->gross - ($txn->balance + $txn->allocated)), 0, t('Transaction balances internally'), 'e-Commerce'); $this->assertEqual(($receipt->amount - ($receipt->balance + $receipt->allocated)), 0, t('Receipt balances internally'), 'e-Commerce'); $this->assertEqual($txn->allocation, EC_ALLOC_COMPLETED, t('Transaction allocation is complete'), 'e-Commerce'); $this->assertEqual($txn->balance, 0, t('Balance of transaction is 0.00'), 'e-Commerce'); $this->assertEqual($receipt->balance, 0, t('Balance of receipt is 0.00'), 'e-Commerce'); } function testOverAllocation() { $account = $this->drupalCreateUser(); $address = array( 'uid' => $account->uid, 'firstname' => $this->randomName(20), 'lastname' => $this->randomName(20), 'street1' => $this->randomName(52), 'street2' => $this->randomName(52), 'zip' => drupal_substr($this->randomName(10), -10), 'city' => $this->randomName(20), 'state' => $this->randomName(20), 'country' => 'US', ); drupal_write_record('ec_address', $address); $product = array( 'type' => 'product', 'ptype' => 'generic', 'price' => '20.00', 'revision' => 1, ); $node = $this->drupalCreateNode($product); $product = clone $node; $product->qty = 1; $params = array( 'customer' => ec_customer_get_by_uid($account->uid), 'items' => array( $product->nid => $product, ), ); $txn = ec_checkout_create_transaction('ec_buynow', $params, $this); $this->assertEqual(($txn->gross - ($txn->balance + $txn->allocated)), 0, t('Transaction balances internally'), 'e-Commerce'); $erid = ec_receipt_build_receipt('transaction', $txn, NULL, 40); $receipt = ec_receipt_load($erid); $alloc[] = array( 'type' => 'transaction', 'id' => $txn->txnid, 'amount' => $receipt->amount, ); ec_receipt_allocate($receipt, $alloc); $txn = ec_store_transaction_load($txn->txnid); $receipt = ec_receipt_load($erid); $this->assertEqual(($txn->gross - ($txn->balance + $txn->allocated)), 0, t('Transaction balances internally'), 'e-Commerce'); $this->assertEqual(($receipt->amount - ($receipt->balance + $receipt->allocated)), 0, t('Receipt balances internally'), 'e-Commerce'); $this->assertEqual($txn->allocation, EC_ALLOC_COMPLETED, t('Transaction allocation is complete'), 'e-Commerce'); $this->assertEqual($txn->balance, 0, t('Balance of transaction is 0.00'), 'e-Commerce'); $this->assertEqual($receipt->balance, 20, t('Balance of receipt is 20.00'), 'e-Commerce'); } function testUnderAllocation() { $account = $this->drupalCreateUser(); $address = array( 'uid' => $account->uid, 'firstname' => $this->randomName(20), 'lastname' => $this->randomName(20), 'street1' => $this->randomName(52), 'street2' => $this->randomName(52), 'zip' => drupal_substr($this->randomName(10), -10), 'city' => $this->randomName(20), 'state' => $this->randomName(20), 'country' => 'US', ); drupal_write_record('ec_address', $address); $product = array( 'type' => 'product', 'ptype' => 'generic', 'price' => '20.00', 'revision' => 1, ); $node = $this->drupalCreateNode($product); $product = clone $node; $product->qty = 1; $params = array( 'customer' => ec_customer_get_by_uid($account->uid), 'items' => array( $product->nid => $product, ), ); $txn = ec_checkout_create_transaction('ec_buynow', $params, $this); $this->assertEqual(($txn->gross - ($txn->balance + $txn->allocated)), 0, t('Transaction balances internally'), 'e-Commerce'); $erid = ec_receipt_build_receipt('transaction', $txn, NULL, 10); $receipt = ec_receipt_load($erid); $alloc[] = array( 'type' => 'transaction', 'id' => $txn->txnid, 'amount' => $txn->gross, ); ec_receipt_allocate($receipt, $alloc); $txn = ec_store_transaction_load($txn->txnid); $receipt = ec_receipt_load($erid); $this->assertEqual(($txn->gross - ($txn->balance + $txn->allocated)), 0, t('Transaction balances internally'), 'e-Commerce'); $this->assertEqual(($receipt->amount - ($receipt->balance + $receipt->allocated)), 0, t('Receipt balances internally'), 'e-Commerce'); $this->assertEqual($txn->allocation, EC_ALLOC_PART, t('Transaction allocation is complete'), 'e-Commerce'); $this->assertEqual($txn->balance, 10, t('Balance of transaction is 10.00'), 'e-Commerce'); $this->assertEqual($receipt->balance, 0, t('Balance of receipt is 0.00'), 'e-Commerce'); } }