2016-07-28 8 views
0

Laravel 5.2で動作するAuthorize.net SDKを取得できません。Authorize.net SDK with Laravel

私は(のvar_dump)応答...私が得るすべては

object(net\authorize\api\contract\v1\ARBCreateSubscriptionResponse)#413 (4) `{ ["subscriptionId":"net\authorize\api\contract\v1\ARBCreateSubscriptionResponse":private]=> NULL ["refId":"net\authorize\api\contract\v1\ANetApiResponseType":private]=> NULL ["messages":"net\authorize\api\contract\v1\ANetApiResponseType":private]=> NULL ["sessionToken":"net\authorize\api\contract\v1\ANetApiResponseType":private]=> NULL }` 

では、誰もがauthorize.netはLaravelでの作業を取得することができましたし、潜在的に、彼らはそれをやった方法私を見るだろうか?シンプルで

私の試み充電

$merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); 
     $merchantAuthentication->setName("snip"); 
     $merchantAuthentication->setTransactionKey("snip"); 
     $refId = 'ref' . time(); 

     $creditCard = new AnetAPI\CreditCardType(); 
     $creditCard->setCardNumber("6011000000000012"); 
     $creditCard->setExpirationDate("2028-12"); 
     $paymentOne = new AnetAPI\PaymentType(); 
     $paymentOne->setCreditCard($creditCard); 

     // Create a transaction 
     $transactionRequestType = new AnetAPI\TransactionRequestType(); 
$transactionRequestType->setTransactionType("authCaptureTransaction"); 
     $transactionRequestType->setAmount(151.51); 
     $transactionRequestType->setPayment($paymentOne); 

     $request = new AnetAPI\CreateTransactionRequest(); 
     $request->setMerchantAuthentication($merchantAuthentication); 
     $request->setTransactionRequest($transactionRequestType); 
     $controller = new AnetController\CreateTransactionController($request); 
     $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); 
     var_dump($response); 
     echo "<br><br>"; 
     if ($response != null) 
     { 
      $tresponse = $response->getTransactionResponse(); 

if (($tresponse != null) && ($tresponse->getResponseCode()=="1")) 
      { 
       echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n"; 
       echo "Charge Credit Card TRANS ID : " . $tresponse->getTransId() . "\n"; 
      } 
      else 
      { 
       echo "Charge Credit Card ERROR : Invalid response\n"; 
      } 
     } 
     else 
     { 
      echo "Charge Credit card Null response returned"; 
     } 

私composer.json

{ 
    "name": "laravel/laravel", 
    "description": "The Laravel Framework.", 
    "keywords": ["framework", "laravel"], 
    "license": "MIT", 
    "type": "project", 
    "require": { 
     "php": ">=5.5.9", 
     "laravel/framework": "5.2.*", 
     "guzzlehttp/guzzle": "^6.0", 
     "ext-curl": "^0.0.0", 
     "authorizenet/authorizenet": "^1.8" 
    }, 
    "require-dev": { 
     "fzaninotto/faker": "~1.4", 
     "mockery/mockery": "0.9.*", 
     "phpunit/phpunit": "~4.0", 
     "symfony/css-selector": "2.8.*|3.0.*", 
     "symfony/dom-crawler": "2.8.*|3.0.*", 
     "goetas/xsd2php": "2.0.x-dev#fdc2ab0bb3f2b3ab796ca567cf8c0f3446a7ea3a" 
    }, 
    "autoload": { 
     "classmap": [ 
      "database" 
     ], 
     "psr-4": { 
      "App\\": "app/" 
     }, 
     "files": ["app/Http/helpers.php"] 
    }, 
    "autoload-dev": { 
     "classmap": [ 
      "tests/TestCase.php" 
     ] 
    }, 
    "scripts": { 
     "post-root-package-install": [ 
      "php -r \"copy('.env.example', '.env');\"" 
     ], 
     "post-create-project-cmd": [ 
      "php artisan key:generate" 
     ], 
     "post-install-cmd": [ 
      "Illuminate\\Foundation\\ComposerScripts::postInstall", 
      "php artisan optimize" 
     ], 
     "post-update-cmd": [ 
      "Illuminate\\Foundation\\ComposerScripts::postUpdate", 
      "php artisan optimize" 
     ] 
    }, 
    "config": { 
     "preferred-install": "dist" 
    }, 
    "repositories": [{ 
     "type": "vcs", 
     "url": "https://github.com/goetas/serializer.git" 
    }] 
} 
+0

とテストの資格情報を作成しましたか? –

+0

@JeremyHarris少なくともトランザクションID。リクエストがnullでないif()ステートメントを参照してください –

+0

コードがプロダクションモードで使用可能な応答を提供していますが、サンドボックスモードでは使用できないようです@JeremyHarris –

答えて

1

私たちはLaravel 5.2プロジェクトでAuthorize.net SDKを使用してください。私たちの作曲家のパッケージはあなたと全く同じです。しかし、単にAuthorizeNetAIMと直接対話します。支払い処理はJobの内部でも行われます。うまくいけば、これはあなたに便利です

public function handle() 
{ 
    $this->aim = new AuthorizeNetAIM(); 

    //functionality to add line items: 
    $this->aim->addLineItem($identifier, $name, null, $quantity, $price_per_item); 

    $this->aim->amount = $this->order->total; 
    $this->aim->card_num = $this->card_ref->card_num 
    $this->aim->exp_date = $this->card_ref->exp_date 
    $this->aim->first_name = $this->card_ref->first_name; 
    $this->aim->last_name = $this->card_ref->last_name; 
    $this->aim->address = $this->order->billing_address_1 . ' ' . $this->order->billing_address_2; 
    $this->aim->city = $this->order->billing_city; 
    $this->aim->state = $this->order->billing_state; 
    $this->aim->zip = $this->order->billing_zip_code; 
    $this->aim->country = $this->order->billing_country; 
    $this->aim->email = $this->order->contact->email; 
    $this->aim->phone = $this->order->contact->phone; 
    $this->aim->ship_to_address = $this->order->shipping_address_1 . ' ' . $this->order->shipping_address_2; 
    $this->aim->ship_to_city = $this->order->shipping_city; 
    $this->aim->ship_to_country = $this->order->shipping_country; 
    $this->aim->ship_to_first_name = $this->order->first_name; 
    $this->aim->ship_to_last_name = $this->order->last_name; 
    $this->aim->ship_to_state = $this->order->shipping_state; 
    $this->aim->ship_to_zip = $this->order->shipping_zip_code; 

    //You may also need to assign additional fields required by your Gateway configuration, do so here: 
    $this->aim->setField('card_code', $this->card_ref->cvc); 
    $this->aim->setField('invoice_num', $this->order->invoice_num); 
    $this->aim->setField('po_num', $this->order->id); 

    //now we assign our "ref" as value so we can rerun the transaction in the event of failure. 
    $this->aim->setCustomField('ref', 'ref' . time()); 

    //Finally we auth and capture 
    $response = $this->aim->authorizeAndCapture(); 

    //now you can dump the response 
    dd($response); 

} 

:ここでは私たちがどのように見えるかの迅速なアイデアがあります。

1

将来この問題が発生した場合に備えて、私は回答を書いています。

authorize.netアカウントがTESTではなくLIVEに設定されているため、コードが機能しませんでした。アカウントがLIVEに設定されている場合、

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

でコードをテストすることはできません。

私は何の応答あなたが得ることを期待しているthis link