2017-05-22 6 views
1

私は基本認証bigcommerceでwebhooksを使用するには?

Bigcommerce::configure(array(
    'store_url' => 'https://store.mybigcommerce.com', 
    'username' => 'admin', 
    'api_key' => 'd81aada4xc34xx3e18f0xxxx7f36ca' 
)); 

との接続を正常に作成することができる午前、https://github.com/bigcommerce/bigcommerce-api-phpで を多くのことを試してみましたが、私は「OAuthの」

In order to obtain the auth_token you would consume Bigcommerce::getAuthToken method 


$object = new \stdClass(); 
$object->client_id = 'xxxxxx'; 
$object->client_secret = 'xxxxx; 
$object->redirect_uri = 'https://app.com/redirect'; 
$object->code = $request->get('code'); 
$object->context = $request->get('context'); 
$object->scope = $request->get('scope'); 

$authTokenResponse = Bigcommerce::getAuthToken($object); 

Bigcommerce::configure(array(
    'client_id' => 'xxxxxxxx', 
    'auth_token' => $authTokenResponse->access_token, 
    'store_hash' => 'xxxxxxx' 
)); 

にしようとすると、それはこのエラーを示しています

Notice: Undefined variable: request in /var/www/html/tests/bigcommerce/test/index.php on line 25 Fatal error: Call to a member function get() on a non-object in /var/www/html/tests/bigcommerce/test/index.php on line 25

誰かが私を助けてくれますか?どのようにPHPで大口商業のwebhooksを使用できますか?

+1

エラーの説明があるようです。 '$ request'は有効範囲にありません。使用するフレームワークに応じて、$ _REQUESTパラメータにアクセスする人が変更されます。これはwebhook登録とは関係ありません。 –

答えて

1

以下は、Laravelで使用されるサンプル関数です。これは、アプリケーションが承認されると起動されます。 $request->get('code')は、純粋に要求パラメータであるため、$_REQUEST['code']に置き換えることができます。

Bigcommerce::configureステップが完了すると、try catchブロックでWebhook登録が開始されます。

public function onAppAuth(Request $request) 
{ 
    $object = new \stdClass(); 
    $object->client_id = env('BC_CLIENT_ID'); 
    $object->client_secret = env('BC_CLIENT_SECRET'); 
    $object->redirect_uri = env('BC_CALLBACK_URL'); 
    $object->code = $request->get('code'); 
    $object->context = $request->get('context'); 
    $object->scope = $request->get('scope'); 
    Bigcommerce::useJson(); 

    $authTokenResponse = Bigcommerce::getAuthToken($object); 

    // configure BC App 
    Bigcommerce::configure([ 
     'client_id' => env('BC_CLIENT_ID'), 
     'auth_token' => $authTokenResponse->access_token, 
     'store_hash' => explode('/', $request->get('context'))[1] 
    ]); 

    Bigcommerce::verifyPeer(false); 

    try { 
     $store_hash = explode('/', $request->get('context'))[1]; 

     // register webhook 
     Bigcommerce::createWebhook([ 
       "scope" => "store/order/created", 
       "destination" => env('APP_URL')."api/order/process", 
       "is_active" => true 
      ]); 

     return view('thankyou'); 

    } catch(Error $error) { 
     echo $error->getCode(); 
     echo $error->getMessage(); 
    } 

} 
関連する問題