2017-05-22 8 views
1

는 내가 기본 인증bigcommerce에서 webhooks를 사용하는 방법?

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

에 성공적으로 연결을 만들 수 있어요하지만 난 "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' 
)); 

그것은이 오류를 보여줍니다 , https://github.com/bigcommerce/bigcommerce-api-php으로 많이 시도 :

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에서 bigcommerce의 webhook을 어떻게 사용할 수 있습니까?

+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(); 
    } 

}