/** * @expectedException Svea\ValidationException * @expectedExceptionMessage -missing value : Description is required. */ public function test_creditOrderRows_creditPyamentplanOrderRows_noDesciription() { $config = Svea\SveaConfig::getDefaultConfig(); $orderRows[] = WebPayItem::orderRow()->setAmountIncVat(10.0)->setVatPercent(25)->setQuantity(1); $orderRows[] = WebPayItem::orderRow()->setAmountIncVat(10.0)->setVatPercent(25)->setQuantity(1); $credit = WebPayAdmin::creditOrderRows($config)->setContractNumber(123123)->setCountryCode('SE')->addCreditOrderRows($orderRows)->creditPaymentplanOrderRows()->prepareRequest(); }
// We wish to credit the entire card order. To do so, we need to credit the order with an amount equal to the original order total. // This can be done by either : // 1) (recommended) specifying a new credit row for the entire original order total amount and passing in the new row to credit, or // 2) specifying that all of the original order rows are to be credited, passing in their number and, as this is a card order, the order rows themselves // 2) instead credit specific order rows, 2): // // First we create a builder object and populate them with the required fields. $firstCreditOrderRowsBuilder = WebPayAdmin::creditOrderRows($myConfig); // To credit the order, we need its transactionid, which we received with the order request response and wrote to file. $myTransactionId = file_get_contents("transactionid.txt"); if (!$myTransactionId) { echo "<pre>Error: transactionid.txt not found, first run cardorder_credit.php to set up the card order. aborting."; die; } $firstCreditOrderRowsBuilder->setOrderId($myTransactionId)->setCountryCode("SE"); $secondCreditOrderRowsBuilder = WebPayAdmin::creditOrderRows($myConfig); $secondCreditOrderRowsBuilder->setOrderId($myTransactionId)->setCountryCode("SE"); // To credit specific order rows, you pass the order rows numbers you wish to credit using setRowsToCredit(). // For card orders, you also need to pass in the numbered order rows themselves using addNumberedOrderRows(). // You can use the WebPayAdmin::queryCardOrder() entrypoint method to get a copy of the original order rows sent to Svea. // Note that these order rows does not update following a successful credit order rows request, even though the // QueryTransactionResponse field creditedamount returned by a queryOrder request will reflect the current credit status. // $queryOrderBuilder = WebPayAdmin::queryOrder($myConfig)->setOrderId($myTransactionId)->setCountryCode("SE"); // query orderrows to pass in creditOrderRows->setNumberedOrderRows() $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest(); if (!$queryResponse->accepted) { echo "<pre>Error: queryOrder failed. aborting."; die; } // The query response holds an array of NumberedOrderRow containing the order rows as sent in the createOrder request
*/ error_reporting(E_ALL); ini_set('display_errors', 'On'); // Include Svea PHP integration package. $svea_directory = "../../src/"; require_once $svea_directory . "Includes.php"; // get config object $myConfig = Svea\SveaConfig::getTestConfig(); //replace with class holding your merchantid, secretword, et al, adopted from package Config/SveaConfig.php // We wish to credit the entire card order. To do so, we need to credit the order with an amount equal to the original order total. // This can be done by either : // 1) (recommended) specifying a new credit row for the entire original order total amount and passing in the new row to credit, or // 2) specifying that all of the original order rows are to be credited, passing in their number and, as this is a card order, the order rows themselves // 1) Using the first method (for 2), see file creditorderrows_with_rows.php: // First we create a builder object and populate them with the required fields. $firstCreditOrderRowsBuilder = WebPayAdmin::creditOrderRows($myConfig); // To credit the order, we need its transactionid, which we received with the order request response and wrote to file. $myTransactionId = file_get_contents("transactionid.txt"); if (!$myTransactionId) { echo "<pre>Error: transactionid.txt not found, first run cardorder_credit.php to set up the card order. aborting."; die; } $firstCreditOrderRowsBuilder->setOrderId($myTransactionId)->setCountryCode("SE"); // Assume that we know that the original order total amount was 1*(100*1.25) + 2*(5.00*1.12) = 125+11.2 = SEK 136.2 (incl. VAT 26.2) // Create a new OrderRow for the credited amount and add it to the builder object using addCreditOrderRow(): $myCreditRow = WebPayItem::orderRow()->setAmountExVat(300)->setVatPercent(25)->setQuantity(1)->setDescription("Credited order #" . $myTransactionId); // Add the new order row to credit to the builder object. $firstCreditOrderRowsBuilder->addCreditOrderRow($myCreditRow); // Then we can send the credit request to Svea: $myCreditRequest = $firstCreditOrderRowsBuilder->creditCardOrderRows(); $myCreditResponse = $myCreditRequest->doRequest();
public function test_creditOrderRows_creditDirectBankOrderRows_returns_CreditTransaction() { $creditOrderRowsBuilder = WebPayAdmin::creditOrderRows(Svea\SveaConfig::getDefaultConfig())->setCountryCode("SE")->setOrderId(123456)->addNumberedOrderRow(TestUtil::createNumberedOrderRow(100.0, 1, 1))->setRowToCredit(1); $request = $creditOrderRowsBuilder->creditDirectBankOrderRows(); $this->assertInstanceOf("Svea\\HostedService\\CreditTransaction", $request); }
public function test_creditOrderRows_creditPyamentplanOrderRows_multipleRows() { $config = Svea\SveaConfig::getDefaultConfig(); $orderInfo = $this->get_orderInfo_sent_inc_vat(1000.0, 25, 1, TRUE); $orderRows[] = WebPayItem::orderRow()->setAmountIncVat(10.0)->setVatPercent(25)->setQuantity(1)->setDescription("row 1"); $orderRows[] = WebPayItem::orderRow()->setAmountIncVat(10.0)->setVatPercent(25)->setQuantity(1)->setDescription("row 2"); $credit = WebPayAdmin::creditOrderRows($config)->setContractNumber($orderInfo->contractNumber)->setCountryCode('SE')->addCreditOrderRows($orderRows)->creditPaymentplanOrderRows()->doRequest(); // logs should createOrderEU (w/priceIncludingVat = true) => deliverOrderRows // => creditOrderRows (w/priceIncludingVat = false) fail => creditOrderRows (w/priceIncludingVat = true) success $this->assertEquals(1, $credit->accepted); }
public function test_creditOrderRows_creditCardOrderRows_allows_orderRow_with_zero_amount() { $dummyorderid = 123456; $orderBuilder = WebPayAdmin::creditOrderRows(Svea\SveaConfig::getDefaultConfig())->setOrderId($dummyorderid)->setCountryCode("SE")->addCreditOrderRow(WebPayItem::orderRow()->setAmountExVat(0.0)->setVatPercent(0)->setQuantity(0)); try { $request = $orderBuilder->creditCardOrderRows()->prepareRequest(); } catch (Exception $e) { // fail on validation error $this->fail("Unexpected validation exception: " . $e->getMessage()); } }