public function testCompletePurchaseNotify()
{
$testPrivateKey = ALIPAY_ASSET_DIR . '/dist/common/rsa_private_key.pem';
$testPublicKey = ALIPAY_ASSET_DIR . '/dist/common/rsa_public_key.pem';
$this->gateway = new AopAppGateway($this->getHttpClient(), $this->getHttpRequest());
$this->gateway->setAppId($this->appId);
$this->gateway->setPrivateKey($this->appPrivateKey);
$this->gateway->setNotifyUrl('https://www.example.com/notify');
$str = '{"total_amount":"0.01","buyer_id":"20882025611234567","trade_no":"201609232100100306021234567","refund_fee":"0.00","notify_time":"2016-09-23 19:12:33","subject":"test","sign_type":"RSA","notify_type":"trade_status_sync","out_trade_no":"2016092313071234567","gmt_close":"2016-09-23 19:08:10","trade_status":"TRADE_FINISHED","gmt_payment":"2016-09-23 19:08:10","sign":"vCAj0n6vUVggDzZUqV4P2IucMeguUMaLBl5Uld7PeLHCo74/d3AcWCNCsGDxtW9Jm7+suyo6Y0jRY7OUi0PKZJre84m2q9Oo30AdgbMFRT91uZFYp9miJGWlQWwHhJDo3cU5iAYf5bnPPYgH8073kTFtmDPmrP9pvEUm3lsroUw=","gmt_create":"2016-09-23 19:08:09","app_id":"20151128001234567","seller_id":"20880114661234567","notify_id":"da3e56af64bcb163f167240dc0f781agge"}';
$str = stripslashes($str);
$data = json_decode($str, true);
$signer = new Signer($data);
$signer->setSort(true);
$signer->setEncodePolicy(Signer::ENCODE_POLICY_QUERY);
$data['sign'] = $signer->signWithRSA($testPrivateKey);
$data['sign_type'] = 'RSA';
$this->gateway->setAlipayPublicKey($testPublicKey);
/**
* @var AopCompletePurchaseResponse $response
*/
$response = $this->gateway->completePurchase(['params' => $data])->send();
$this->assertEquals('{"total_amount":"0.01","buyer_id":"20882025611234567","trade_no":"201609232100100306021234567","refund_fee":"0.00","notify_time":"2016-09-23 19:12:33","subject":"test","sign_type":"RSA","notify_type":"trade_status_sync","out_trade_no":"2016092313071234567","gmt_close":"2016-09-23 19:08:10","trade_status":"TRADE_FINISHED","gmt_payment":"2016-09-23 19:08:10","sign":"Xa2NyOsxOBjW\\/q\\/RUFZhii2epa4B3ka+2aGsG8knqkiCD8llXrTDm11QtGkSRVw\\/hbfcgFPiTkuaKnaaDu\\/UfypsVSHToy28PiH5xkBSSd6zHNZCP\\/jvjzOa6GPf4tIpfYNVvjaRMRcbn+TRlOFtHOnMMubjsg7K52P+LCugZIA=","gmt_create":"2016-09-23 19:08:09","app_id":"20151128001234567","seller_id":"20880114661234567","notify_id":"da3e56af64bcb163f167240dc0f781agge"}', json_encode($response->data()));
$this->assertEquals('2016092313071234567', $response->data('out_trade_no'));
$this->assertTrue($response->isSuccessful());
$this->assertTrue($response->isPaid());
$this->assertEquals('201609232100100306021234567', $response->getData()['trade_no']);
}