-
Notifications
You must be signed in to change notification settings - Fork 155
Aop APP Gateway
Max Sky edited this page May 15, 2019
·
7 revisions
/**
* @var AopAppGateway $gateway
*/
$gateway = Omnipay::create('Alipay_AopApp');
$gateway->setSignType('RSA2'); //RSA/RSA2
$gateway->setAppId('the_app_id');
$gateway->setPrivateKey('the_app_private_key');
$gateway->setAlipayPublicKey('the_alipay_public_key');
$gateway->setNotifyUrl('https://www.example.com/notify');
$request = $gateway->purchase();
$request->setBizContent([
'subject' => 'test',
'out_trade_no' => date('YmdHis') . mt_rand(1000, 9999),
'total_amount' => '0.01',
'product_code' => 'QUICK_MSECURITY_PAY',
]);
/**
* @var AopTradeAppPayResponse $response
*/
$response = $request->send();
$orderString = $response->getOrderString();
[[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) {
NSLog(@"reslut = %@",resultDic);
}];
PayTask alipay = new PayTask(PayDemoActivity.this);
Map<String, String> result = alipay.payV2(orderString, true);
$request = $gateway->completePurchase();
$request->setParams([
'memo' => '',
'result' => '{\"alipay_trade_app_pay_response\":{\"code\":\"10000\",\"msg\":\"Success\",\"app_id\":\"20151128008123456\",\"auth_app_id\":\"20151128008123456\",\"charset\":\"UTF-8\",\"timestamp\":\"2016-09-23 18:32:16\",\"total_amount\":\"0.01\",\"trade_no\":\"2016092321001003060123456789\",\"seller_id\":\"2088011466123456789\",\"out_trade_no\":\"201609231231447556\"},\"sign\":\"Q5n3zKIBzhBobd6Z6mP69ZvaBlVxkWOiti2ZCRBRhfEH8/sCWE89Iev94K++QH8W9Zakn9dXTq2tR0O5UWLS1XXgiSd+vUTMQNksxjddI39MQnbJ1hxEtwP5GcWzxeY9YRjXXJdzgdf/xmRS7uRQWv52cGYStlCNN/dianZmuDk=\",\"sign_type\":\"RSA\"}',
'resultStatus' => '9000'
]);
/**
* @var AopCompletePurchaseResponse $response
*/
try {
$response = $request->send();
if($response->isPaid()){
/**
* Payment is successful
*/
}else{
/**
* Payment is not successful
*/
}
} catch (Exception $e) {
/**
* Payment is not successful
*/
}
try {
/** @var AopCompletePurchaseResponse $response */
$response = $gateway->completePurchase()->setParams($_POST)->send();
} catch (InvalidRequestException $e) {
/** Payment is not successful */
die('fail');
}
if ($response->isPaid()) {
/** Payment is successful */
die('success'); //The response should be 'success' only
} else {
/** Payment is not successful */
die('fail');
}
try {
/** @var AopCompleteRefundResponse $response */
$response = $gateway->completeRefund()->setParams($_POST)->send();
} catch (InvalidRequestException $e) {
/** Refund is not successful */
die('fail');
}
if ($response->isRefunded()) {
/** Refund is successful */
die('success'); //The response should be 'success' only
} else {
/** Refund is not successful */
die('fail');
}