如何在auth中设置订单发票编号和说明仅继续交易类型?

时间:2018-03-06 10:20:44

标签: php paypal paypal-sandbox authorize.net

如何在AuthorizeNet中使用Paypal express checkout更新发票号和说明,并使用交易类型“authOnlyContinueTransaction”或“authCaptureContinueTransaction”。需要在PHP中完成。

我尝试了以下代码:

$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
    $merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
    $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);

    // Set the transaction's refId
    $refId = 'ref' . time();

    // Set PayPal compatible merchant credentials
    $paypal_type = new AnetAPI\PayPalType();
    $paypal_type->setPayerID($payerId);

    $paypal_type->setSuccessUrl("http://www.merchanteCommerceSite.com/Success/TC25262");
    $paypal_type->setCancelUrl("http://www.merchanteCommerceSite.com/Success/TC25262");

    $payment_type = new AnetAPI\PaymentType();
    $payment_type->setPayPal($paypal_type);

    // Order info
    $order = new AnetAPI\OrderType();
    $order->setInvoiceNumber("101");
    $order->setDescription("Shirts");

    //create a transaction
    $transactionRequestType = new AnetAPI\TransactionRequestType();
    $transactionRequestType->setTransactionType("authOnlyContinueTransaction");
    $transactionRequestType->setRefTransId($transactionId);
    $transactionRequestType->setAmount(4.34);
    $transactionRequestType->setPayment($payment_type);
    $transactionRequestType->setOrder($order);

    $request = new AnetAPI\CreateTransactionRequest();
    $request->setMerchantAuthentication($merchantAuthentication);
    $request->setRefId($refId);
    $request->setTransactionRequest($transactionRequestType);

    $controller = new AnetController\CreateTransactionController($request);

    $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);

    if ($response != null) {
        if ($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK) {
            $tresponse = $response->getTransactionResponse();

            if ($tresponse != null && $tresponse->getMessages() != null) {
                echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n";
                echo "TRANS ID  : " . $tresponse->getTransId() . "\n";
                echo "Payer ID : " . $tresponse->getSecureAcceptance()->getPayerID();
                echo "Description : " . $tresponse->getMessages()[0]->getDescription() . "\n";
            } else {
                echo "Transaction Failed \n";
                if ($tresponse->getErrors() != null) {
                    echo " Error code  : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
                    echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
                }
            }
        } else {
            echo "Transaction Failed \n";
            $tresponse = $response->getTransactionResponse();
            if ($tresponse != null && $tresponse->getErrors() != null) {
                echo " Error code  : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
                echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
            } else {
                echo " Error code  : " . $response->getMessages()->getMessage()[0]->getCode() . "\n";
                echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n";
            }
        }
    } else {
        echo  "No response returned \n";
    }

无法更改发票编号和订单说明。 早些时候,使用Transaction类型“authOnlyTransaction”或“authCaptureTransaction”能够更新发票号和说明。

如何使用事务类型更新相同的内容是“authOnlyContinueTransaction”或“authCaptureContinueTransaction”?

我引用了https://developer.authorize.net/api/reference/index.html#PayPal-express-checkout

1 个答案:

答案 0 :(得分:1)

你好像误解了这个流程。您无法在 authOnlyContinueTransaction authCaptureContinueTransaction 中传递订单对象。流程是这样的。

  1. 创建交易并获取参考ID
  2. 在上述方法中传递引用的id以确认它
  3. 或者,最好使用允许您设置订单的createTransactionRequest