Beispiel #1
0
 public function testRunCallback()
 {
     // Create order
     $payload = Processor::run(Payload::create(['gateway' => 'test_gateway', 'method' => 'test_pay', 'action' => 'payRequest', 'data' => ['order_prefix' => 'CALLBACK', 'trade_id' => md5(microtime()), 'product_name' => 'Test product', 'client_id' => 'test_client', 'user_identifier' => 'Test User', 'amount' => $amount = 1]]));
     $this->assertInstanceOf(Payload::class, $payload);
     $this->assertInstanceOf(Result::class, $result = $payload->getResult());
     $this->assertInstanceOf(Order::class, $order = $result->getOrder());
     $this->assertEquals($order::STATUS_PENDING, $order->getStatus());
     $this->assertEquals($amount, $order->getAmount());
     $this->assertEquals($amount, $order->getCashToPay());
     // Send callback data
     $callback = Processor::run(Payload::create(['gateway' => 'test_gateway', 'method' => 'test_pay', 'action' => 'callback', 'data' => ['order_id' => $order->getOrderId(), 'amount' => $order->getAmount(), 'status' => 'complete', 'sign' => 'any-sign-would-work']]));
     $this->assertInstanceOf(Payload::class, $callback);
     $this->assertInstanceOf(Result::class, $result = $callback->getResult());
     $this->assertInstanceOf(Order::class, $order = $result->getOrder());
     $this->assertEquals($order::STATUS_COMPLETE, $order->getStatus());
     $this->assertEquals($amount, $order->getAmount());
     $this->assertEquals($amount, $order->getCashPaid());
     $this->assertEquals(0, $order->getCashToPay());
 }
Beispiel #2
0
 public function testVerifyCallbackSign()
 {
     $payload = Processor::run(Payload::create(['gateway' => 'alipay', 'method' => 'mobile_web', 'action' => 'payRequest', 'data' => ['trade_id' => 'TEST-ALIPAY-BAD-CALLBACK-PARAMS', 'product_name' => 'Test product', 'client_id' => 'test_client', 'user_identifier' => 'Test User', 'amount' => $amount = 1]]));
     $this->assertInstanceOf(Payload::class, $payload);
     $this->assertInstanceOf(Result::class, $result = $payload->getResult());
     $this->assertInstanceOf(Order::class, $order = $result->getOrder());
     $this->assertEmpty($order->getStringMessages());
     $this->assertEquals($order::STATUS_PENDING, $order->getStatus());
     $callback = Processor::run(Payload::create(['gateway' => 'alipay', 'method' => 'mobile_web', 'action' => 'callback', 'data' => ['discount' => '0.00', 'payment_type' => '1', 'subject' => $order->getProductName(), 'trade_no' => date('YmdHis') . '123456789012', 'buyer_email' => '*****@*****.**', 'gmt_create' => $time = date('Y-m-d H:i:s', $order->getCreatedAt()), 'notify_type' => 'trade_status_sync', 'quantity' => '1', 'out_trade_no' => $order->getOrderId(), 'seller_id' => $order->getOrderData('alipay_request.partner'), 'notify_time' => date('Y-m-d H:i:s'), 'body' => $order->getProductName(), 'trade_status' => 'TRADE_CLOSED', 'is_total_fee_adjust' => 'N', 'total_fee' => $amount, 'gmt_payment' => $time, 'seller_email' => $order->getOrderData('alipay_request.seller_id'), 'gmt_close' => $time, 'price' => $amount, 'buyer_id' => 'BUYER_ID', 'notify_id' => 'f2b0c402904bc47d2913fd9ad085731jh2', 'use_coupon' => 'N', 'sign_type' => 'RSA', 'sign' => 'bad-sign']]));
     $this->assertInstanceOf(Payload::class, $callback);
     $this->assertInstanceOf(Result::class, $result = $callback->getResult());
     $this->assertInstanceOf(CallbackException::class, $error = $result->getError());
     $this->assertEquals(CallbackException::INVALID_SIGN, $error->getCode());
 }