我在沙盒帐户Authorize.Net上创建了Webhook,在这种情况下,我需要事件(net.authorize.payment.authcapture.created
的响应,因此需要订阅自动交易的响应。在此响应中,我没有获取订阅ID,但得到了交易ID如果我进一步使用事务ID通过GetTransactionDetailsController
(获取事务API Authorize.Net)函数获取订阅ID,它将检索事务但订阅为null。如何使用事务响应获取订阅ID或使用(net.authorize.payment.authcapture.create
d)事件响应获取订阅ID?
public function getAutoshipResponse(Request $request)
{
define('AUTHNET_SIGNATURE', config('services.authorize.signature'));
$payload = file_get_contents('php://input');
Log::info("payload is === ". $payload);
$headers = $this->getHeaders();
$webhook = new AuthnetWebhook(AUTHNET_SIGNATURE, $payload, $headers);
if ($webhook->isValid())
{
$eventtype = $webhook->eventType;
$entityName = $webhook->payload->entityName;
$this->getTransactionDetails($transactionId)
}
}
public function getTransactionDetails($transactionId)
{
$transactionId = '60127785891';
$merchantAuthentication = $this->setMerchantAuthentication();
$refId = 'ref' . time();// Set the transaction's refId
$request = new AnetAPI\GetTransactionDetailsRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setTransId($transactionId);
$controller = new AnetController\GetTransactionDetailsController($request);
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
$subscriptionId = $response->getTransaction()->getSubscription();
$json = json_encode($response->getTransaction());
dd($response);
}
响应:
GetTransactionDetailsResponse {#720 ▼
-transaction: TransactionDetailsType {#913 ▼
-transId: "60127785891"
-refTransId: null
-splitTenderId: null
-submitTimeUTC: DateTime @1569416668 {#917 ▶}
-submitTimeLocal: DateTime @1569391468 {#918 ▶}
-transactionType: "authCaptureTransaction"
-transactionStatus: "settledSuccessfully"
-responseCode: 1
-responseReasonCode: 1
-subscription: null
-responseReasonDescription: "Approval"
}