/** * @param Order $order * @param float $callbackAmount * @param int $errorCode * @return bool */ public function verifyCallbackAmount($order, $callbackAmount, $errorCode = CallbackException::INVALID_AMOUNT) { $amount = 1 * $order->getAmount(); if (round($amount - $callbackAmount, 2) != 0) { $this->throwCallbackException(__('Invalid callback amount [%callbackAmount%], should be [%amount%]', ['amount' => $amount, 'callbackAmount' => $callbackAmount]), $errorCode); } }
public function initialize() { parent::initialize(); $db = Db::connection(); $db->tableExists($this->_table) or $this->createTable(); $db->delete($this->_table); }
protected function getRequestData(Order $order) { return ['service' => $this->service, 'partner' => $this->config['partner'], '_input_charset' => $this->config['charset'], 'sign_type' => $this->config['sign_type'], 'notify_url' => url($this->config['notify_url'], null, true), 'return_url' => url($this->config['return_url'], null, true), 'out_trade_no' => $order->getOrderId(), 'subject' => $order->getProductName(), 'total_fee' => $order->getAmount(), 'seller_id' => $this->config['seller_id'], 'payment_type' => 1]; }
public function testFailOrder() { $tradeId = md5(microtime()); $order = Order::prepare(['order_prefix' => 'FAILED', 'amount' => '1', 'trade_id' => $tradeId, 'product_name' => 'Test product', 'user_identifier' => 'Test User', 'client_id' => 'test_client', 'payment_gateway' => 'alipay', 'payment_method' => 'mobile_web', 'currency' => 'CNY', 'amount_in_currency' => '1']); $this->assertTrue($order->save(), $order->getStringMessages()); $order->fail(); $this->assertTrue($order->save(), $order->getStringMessages()); $this->assertEquals($order::STATUS_FAILING, $order->getStatus()); $e = null; try { $order->fail(); } catch (OrderException $e) { } $this->assertInstanceOf(OrderException::class, $e); $this->assertEquals($e::ERROR_CODE_ORDER_CANNOT_BE_FAILED, $e->getCode()); $order->confirmFail(); $this->assertTrue($order->save(), $order->getStringMessages()); $this->assertEquals($order::STATUS_FAILED, $order->getStatus()); $e = null; try { $order->confirmFail(); } catch (OrderException $e) { } $this->assertInstanceOf(OrderException::class, $e); $this->assertEquals($e::ERROR_CODE_ORDER_CANNOT_BE_FAILED, $e->getCode()); }