Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP授权具有多个项目/产品的.NET AIM_Php_Payment Gateway_Authorize.net - Fatal编程技术网

使用PHP授权具有多个项目/产品的.NET AIM

使用PHP授权具有多个项目/产品的.NET AIM,php,payment-gateway,authorize.net,Php,Payment Gateway,Authorize.net,您好,我正在开发一个web应用程序,需要将其与Authorize.NET AIM集成。我已经测试了Authorize.NET提供的代码,它可以很好地用于单个产品。此代码有一个用于行项目的选项,默认情况下会进行注释。我取消了注释,然后使用了它,但它只显示单个产品处理,没有行项目处理 请参阅Authorize.NET AIM示例代码 // By default, this sample code is designed to post to our test server for // develo

您好,我正在开发一个web应用程序,需要将其与Authorize.NET AIM集成。我已经测试了Authorize.NET提供的代码,它可以很好地用于单个产品。此代码有一个用于行项目的选项,默认情况下会进行注释。我取消了注释,然后使用了它,但它只显示单个产品处理,没有行项目处理

请参阅Authorize.NET AIM示例代码

// By default, this sample code is designed to post to our test server for
// developer accounts: https://test.authorize.net/gateway/transact.dll
// for real accounts (even in test mode), please make sure that you are
// posting to: https://secure.authorize.net/gateway/transact.dll
$post_url = "https://test.authorize.net/gateway/transact.dll";

$post_values = array(

// the API Login ID and Transaction Key must be replaced with valid values
"x_login"           => "API_LOGIN_ID",
"x_tran_key"        => "TRANSACTION_KEY",

"x_version"         => "3.1",
"x_delim_data"      => "TRUE",
"x_delim_char"      => "|",
"x_relay_response"  => "FALSE",

"x_type"            => "AUTH_CAPTURE",
"x_method"          => "CC",
"x_card_num"        => "4111111111111111",
"x_exp_date"        => "0115",

"x_amount"          => "19.99",
"x_description"     => "Sample Transaction",

"x_first_name"      => "John",
"x_last_name"       => "Doe",
"x_address"         => "1234 Street",
"x_state"           => "WA",
"x_zip"             => "98004"
// Additional fields can be added here as outlined in the AIM integration
// guide at: http://developer.authorize.net
   );

   // This section takes the input fields and converts them to the proper format
   // for an http post.  For example: "x_login=username&x_tran_key=a1B2c3D4"
   $post_string = "";
   foreach( $post_values as $key => $value )
   { $post_string .= "$key=" . urlencode( $value ) . "&"; }
   $post_string = rtrim( $post_string, "& " );

   // The following section provides an example of how to add line item details to
   // the post string.  Because line items may consist of multiple values with the
   // same key/name, they cannot be simply added into the above array.
   //
   // This section is commented out by default.

   $line_items = array(
   "item1<|>golf balls<|><|>2<|>18.95<|>Y",
   "item2<|>golf bag<|>Wilson golf carry bag, red<|>1<|>39.99<|>Y",
   "item3<|>book<|>Golf for Dummies<|>1<|>21.99<|>Y");

   foreach( $line_items as $value )
    { $post_string .= "&x_line_item=" . urlencode( $value ); }


   // This sample code uses the CURL library for php to establish a connection,
   // submit the post, and record the response.
   // If you receive an error, you may want to ensure that you have the curl
   // library enabled in your php configuration
   $request = curl_init($post_url); // initiate curl object
    curl_setopt($request, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from    response
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
curl_setopt($request, CURLOPT_POSTFIELDS, $post_string); // use HTTP POST to send form data
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response.
$post_response = curl_exec($request); // execute curl post and store results in $post_response
// additional options may be required depending upon your server configuration
// you can find documentation on curl options at http://www.php.net/curl_setopt
    curl_close ($request); // close curl object

    // This line takes the response and breaks it into an array using the specified        delimiting character
    $response_array = explode($post_values["x_delim_char"],$post_response);

    // The results are output to the screen in the form of an html numbered list.
    echo "<OL>\n";
    foreach ($response_array as $value)
    {
      echo "<LI>" . $value . "&nbsp;</LI>\n";
      $i++;
    }
    echo "</OL>\n";
     // individual elements of the array could be accessed to read certain response
     // fields.  For example, response_array[0] would return the Response Code,
     // response_array[2] would return the Response Reason Code.
     // for a list of response fields, please review the AIM Implementation Guide
//默认情况下,此示例代码旨在发布到我们的测试服务器,以便
//开发商账户:https://test.authorize.net/gateway/transact.dll
//对于真实帐户(即使在测试模式下),请确保
//邮寄至:https://secure.authorize.net/gateway/transact.dll
$post_url=”https://test.authorize.net/gateway/transact.dll";
$post_值=数组(
//API登录ID和事务密钥必须替换为有效值
“x_登录”=>“API_登录ID”,
“x_交易密钥”=>“交易密钥”,
“x_版本”=>“3.1”,
“x_delim_数据”=>“真”,
“x_delim_char”=>“|”,
“x_中继_响应”=>“错误”,
“x_type”=>“AUTH_CAPTURE”,
“x_方法”=>“抄送”,
“x_card_num”=>“4111111111”,
“x_exp_date”=>“0115”,
“x_金额”=>“19.99”,
“x_说明”=>“样本交易”,
“x_名字”=>“约翰”,
“x_姓氏”=>“Doe”,
“x_地址”=>“1234街”,
“x_州”=>“WA”,
“x_-zip”=>“98004”
//如AIM集成中所述,可以在此处添加其他字段
//指南地址:http://developer.authorize.net
);
//本节获取输入字段并将其转换为正确的格式
//对于http post。例如:“x_login=username&x_tran_key=a1B2c3D4”
$post_string=“”;
foreach($key=>$value的post_值)
{$post_string.=“$key=”.urlencode($value)。“&”}
$post_string=rtrim($post_string,&”);
//以下部分提供了如何将行项目详细信息添加到的示例
//邮政字符串。因为行项目可能由多个具有
//相同的键/名称,不能简单地将它们添加到上述数组中。
//
//默认情况下,此部分被注释掉。
$line\u items=数组(
“项目1Golf balls218.95Y”,
“item2golf bagWilson高尔夫手提包,红色139.99Y”,
“第3项BookGolf for Dummies121.99Y”);
foreach($value作为第_行项目)
{$post_string.=“&x_line_item=“.urlencode($value);}
//此示例代码使用php的CURL库建立连接,
//提交帖子,并记录回复。
//如果您收到错误,您可能希望确保您有卷曲
//在php配置中启用库
$request=curl\u init($post\u url);//启动卷曲对象
curl_setopt($request,CURLOPT_头,0);//设置为0可从响应中删除标题信息
curl_setopt($request,CURLOPT_RETURNTRANSFER,1);//返回响应数据而不是TRUE(1)
curl_setopt($request,CURLOPT_POSTFIELDS,$post_string);//使用HTTP POST发送表单数据
curl_setopt($request,CURLOPT_SSL_VERIFYPEER,FALSE);//如果没有得到网关响应,请取消对此行的注释。
$post_response=curl_exec($request);//执行curl post并将结果存储在$post_response中
//根据您的服务器配置,可能需要其他选项
//您可以在以下位置找到有关curl选项的文档:http://www.php.net/curl_setopt
卷曲关闭($request);//闭合卷曲对象
//此行接受响应并使用指定的定界字符将其拆分为一个数组
$response\u array=explode($post\u值[“x\u delim\u char”],$post\u response);
//结果以html编号列表的形式输出到屏幕。
回音“\n”;
foreach($response\u数组作为$value)
{
回显“
  • ”$value.
  • \n”; $i++; } 回音“\n”; //可以访问数组的各个元素以读取特定响应 //田地。例如,响应_数组[0]将返回响应代码, //响应_数组[2]将返回响应原因代码。 //有关响应字段的列表,请查看AIM实施指南
    请帮助使用Authorize.NET AIM发布多个项目


    提前感谢。

    您在哪里查找行项目?它不会出现在Authorize.NET返回的响应中。只有在您登录授权.NET时,才能在“交易详细信息”页面上找到它。

    您在哪里查找行项目?它不会出现在Authorize.NET返回的响应中。只有在登录到.NET授权时,您才能在事务详细信息页面上找到它。

    我建议使用他们的SDK而不是CURL调用

    那么代码应该是这样的:

    <?php
    require_once 'anet_php_sdk/AuthorizeNet.php'; // Make sure this path is correct.
    $transaction = new AuthorizeNetAIM('YOUR_API_LOGIN_ID', 'YOUR_TRANSACTION_KEY');
    $transaction->amount = '9.99';
    $transaction->card_num = '4007000000027';
    $transaction->exp_date = '10/16';
    
    $response = $transaction->authorizeAndCapture();
    
    if ($response->approved) {
      echo "<h1>Success! The test credit card has been charged!</h1>";
      echo "Transaction ID: " . $response->transaction_id;
    } else {
      echo $response->error_message;
    }
    ?>
    
    所有这些Authorize.net列出项目的行为都有一点问题,因此如果该解决方案不起作用,请查看:
    我建议使用他们的SDK而不是CURL调用

    那么代码应该是这样的:

    <?php
    require_once 'anet_php_sdk/AuthorizeNet.php'; // Make sure this path is correct.
    $transaction = new AuthorizeNetAIM('YOUR_API_LOGIN_ID', 'YOUR_TRANSACTION_KEY');
    $transaction->amount = '9.99';
    $transaction->card_num = '4007000000027';
    $transaction->exp_date = '10/16';
    
    $response = $transaction->authorizeAndCapture();
    
    if ($response->approved) {
      echo "<h1>Success! The test credit card has been charged!</h1>";
      echo "Transaction ID: " . $response->transaction_id;
    } else {
      echo $response->error_message;
    }
    ?>
    
    所有这些Authorize.net列出项目的行为都有一点问题,因此如果该解决方案不起作用,请查看:

    您也可以尝试使用比他们的SDK更轻、更易于使用的SDK。它甚至包括一个示例,演示如何添加多个行项目:

    require('../../config.inc.php');
    require('../../AuthnetXML.class.php');
    
    $xml = new AuthnetXML(AUTHNET_LOGIN, AUTHNET_TRANSKEY, AuthnetXML::USE_DEVELOPMENT_SERVER);
    $xml->createTransactionRequest(array(
        'refId' => rand(1000000, 100000000),
        'transactionRequest' => array(
            'transactionType' => 'authCaptureTransaction',
            'amount' => 5,
            'payment' => array(
                'creditCard' => array(
                    'cardNumber' => '4111111111111111',
                    'expirationDate' => '122016',
                    'cardCode' => '999',
                ),
            ),
            'order' => array(
                'invoiceNumber' => '1324567890',
                'description' => 'this is a test transaction',
            ),
            'lineItems' => array(
                'lineItem' => array(
                    0 => array(
                        'itemId' => '1',
                        'name' => 'vase',
                        'description' => 'Cannes logo',
                        'quantity' => '18',
                        'unitPrice' => '45.00'
                    ),
                    1 => array(
                        'itemId' => '2',
                        'name' => 'desk',
                        'description' => 'Big Desk',
                        'quantity' => '10',
                        'unitPrice' => '85.00'
                    )
                )
            ),
            'tax' => array(
               'amount' => '4.26',
               'name' => 'level2 tax name',
               'description' => 'level2 tax',
            ),
            'duty' => array(
               'amount' => '8.55',
               'name' => 'duty name',
               'description' => 'duty description',
            ),
            'shipping' => array(
               'amount' => '4.26',
               'name' => 'level2 tax name',
               'description' => 'level2 tax',
            ),
            'poNumber' => '456654',
            'customer' => array(
               'id' => '18',
               'email' => 'someone@blackhole.tv',
            ),
            'billTo' => array(
               'firstName' => 'Ellen',
               'lastName' => 'Johnson',
               'company' => 'Souveniropolis',
               'address' => '14 Main Street',
               'city' => 'Pecan Springs',
               'state' => 'TX',
               'zip' => '44628',
               'country' => 'USA',
            ),
            'shipTo' => array(
               'firstName' => 'China',
               'lastName' => 'Bayles',
               'company' => 'Thyme for Tea',
               'address' => '12 Main Street',
               'city' => 'Pecan Springs',
               'state' => 'TX',
               'zip' => '44628',
               'country' => 'USA',
            ),
            'customerIP' => '192.168.1.1',
            'transactionSettings' => array(
                'setting' => array(
                    0 => array(
                        'settingName' =>'allowPartialAuth',
                        'settingValue' => 'false'
                    ),
                    1 => array(
                        'settingName' => 'duplicateWindow',
                        'settingValue' => '0'
                    ),
                    2 => array(
                        'settingName' => 'emailCustomer',
                        'settingValue' => 'false'
                    ),
                    3 => array(
                        'settingName' => 'recurringBilling',
                        'settingValue' => 'false'
                    ),
                    4 => array(
                        'settingName' => 'testRequest',
                        'settingValue' => 'false'
                    )
                )
            ),
            'userFields' => array(
                'userField' => array(
                    'name' => 'MerchantDefinedFieldName1',
                    'value' => 'MerchantDefinedFieldValue1',
                ),
                'userField' => array(
                    'name' => 'favorite_color',
                    'value' => 'blue',
                ),
            ),
        ),
    ));
    ?>
    
    <!DOCTYPE html>
    <html>
    <html lang="en">
        <head>
            <title>AIM :: Authorize and Capture</title>
            <style type="text/css">
                table
                {
                    border: 1px solid #cccccc;
                    margin: auto;
                    border-collapse: collapse;
                    max-width: 90%;
                }
    
                table td
                {
                    padding: 3px 5px;
                    vertical-align: top;
                    border-top: 1px solid #cccccc;
                }
    
                pre
                {
                    overflow-x: auto; /* Use horizontal scroller if needed; for Firefox 2, not needed in Firefox 3 */
                    white-space: pre-wrap; /* css-3 */
                    white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
                    white-space: -pre-wrap; /* Opera 4-6 */
                    white-space: -o-pre-wrap; /* Opera 7 */ /*
                    width: 99%; */
                    word-wrap: break-word; /* Internet Explorer 5.5+ */
                }
    
                table th
                {
                    background: #e5e5e5;
                    color: #666666;
                }
    
                h1, h2
                {
                    text-align: center;
                }
            </style>
        </head>
        <body>
            <h1>
                AIM :: Authorize and Capture
            </h1>
            <h2>
                Results
            </h2>
            <table>
                <tr>
                    <th>Response</th>
                    <td><?php echo $xml->messages->resultCode; ?></td>
                </tr>
                <tr>
                    <th>code</th>
                    <td><?php echo $xml->messages->message->code; ?></td>
                </tr>
                <tr>
                    <th>Successful?</th>
                    <td><?php echo ($xml->isSuccessful()) ? 'yes' : 'no'; ?></td>
                </tr>
                <tr>
                    <th>Error?</th>
                    <td><?php echo ($xml->isError()) ? 'yes' : 'no'; ?></td>
                </tr>
                <tr>
                    <th>authCode</th>
                    <td><?php echo $xml->transactionResponse->authCode; ?></td>
                </tr>
                <tr>
                    <th>transId</th>
                    <td><?php echo $xml->transactionResponse->transId; ?></td>
                </tr>
            </table>
            <h2>
                Raw Input/Output
            </h2>
    <?php
        echo $xml;
    ?>
        </body>
    </html>
    
    require('../../config.inc.php');
    需要('../AuthnetXML.class.php');
    $xml=新的AuthnetXML(AUTHNET_登录,AUTHNET_转换键,AuthnetXML::使用开发服务器);
    $xml->createTransactionRequest(数组(
    “refId”=>兰特(1000000000000),
    “transactionRequest”=>数组(
    'transactionType'=>'AuthCaptureTransation',
    “金额”=>5,
    “付款”=>数组(
    “信用卡”=>数组(
    “卡号”=>“4111111111”,
    'expirationDate'=>'122016',
    'cardCode'=>'999',
    ),
    ),
    “顺序”=>数组(
    “发票编号”=>“1324567890”,
    
    { lineItems:[
      { lineItem: { ..Line item data..}},
      { lineItem: { ..Line item data..}}
    ]}
    
    { lineItems:
      { lineItem: [{ ..Line item data..},
                   { ..Line item data..}]
    }}
    
    { lineItems:[
      { lineItem: { ..Line item data..}}   
    ]}
    
    { lineItems:[
      { lineItem: { ..Line item data..}},
      { lineItem: { ..Line item data..}}
    ]}
    
    {[
       {lineItems: { lineItem: { ..Line item data..}}},
       {lineItems: { lineItem: { ..Line item data..}}}
    ]}