2016-12-30 4 views
0

私の英語はすみません。カスタマーストライプを共有する際にエラーが発生し、PHPを使用して料金を作成します

スタンドアロンアカウントを使用して接続アカウントをストライプで作成しようとしています。ストライプでこの記事を使用してアカウントを接続しています:Sample OAuth Applications私は3つのアカウントを持っています:A)メインアカウント。このアカウントには、アプリのクライアントがあります。アカウントBとアカウントCはアカウントAに接続されている他のアカウントです(この2つのアカウントはアカウントAの設定で接続されていますが、2つのアカウントが既に接続されていることがわかります)。すべてのユーザーのアプリはアカウントAにあり、私たちはアカウントBとCに共有したい、それが私たちの目標です。

アカウントが接続されると、acces_tokenと更新トークンをDBに保存します。共有顧客のdocsは、顧客のクレジットカード情報を使用してトークンを作成するためにcustomer_idとaccount_idでトークンを作成する必要があると言いますが、コードを実行するとエラーを返します:

提供されたキー ' sk_test _ ******************* uJ3l 'はアカウント' acct _-------------- '(またはそのアカウント)にアクセスできません存在しない)。アプリケーションへのアクセスが取り消された可能性があります。

変数の複数の組み合わせがapiに渡され、結果が常にエラーを返します。

この場合、何が間違っていますか。手伝ってくれる???

この

は、我々が使用したコードです:

public function createtransaction($customer_id, $paymentDesc, $destinationAccount) { 

     $errors = array(); 
     try { 
      $secret_key = $this->get_secret_key(); 

      \Stripe\Stripe::setApiKey($secret_key); 

      // THIS ONLY FOR TESTING PURPOSE. WE WANT SEE IF CAN ACCESS TO CONNECTED ACCOUNT 
      // Fetching an account just needs the ID as a parameter 
      // WHIT ACCESS_TOKEN WORKS THE RETRIEVE METHOD 
      // $account = \Stripe\Account::retrieve('access_token_from_db'); 
      // WHIT ACCOUNT_ID DOES NOT. RETURNS AN ERROR 
      // $account = \Stripe\Account::retrieve('acct_***********'); 
      // echo "<pre>------"; 
      // print_r($account); 
      // echo "-----</pre>"; 


      // HERE ONLY WE CAN TEST IF WE CAN CREATE A CUSTOMER. THIS IS ONLY TO CHECK IF THE ACCOUNT IS CONNECTED. THE CUSTOMER ALREADY EXISTS IN MAIN ACCOUNT 
      // Recommended: sending API key with every request 
      // \Stripe\Customer::create(
      // array("description" => "[email protected]"), 
      // array("api_key" => 'sk_test_***************') // account's access token from the Connect flow 
      // SAME. WITH stripe_account DOES NOT WORK. WHIT api_key PARAM WORKS WELL 
      //); 

      // THE DOCS SAYS WE NEED CREATE A TOEKN WITH customer AND stripe_account, BUT IT RETURNS AN ERROR OF PERMISSION 
      // Create a Token from the existing customer on the platform's account 
      // $token = \Stripe\Token::create(
      // array("customer" => $customer_id), 
      // array("stripe_account" => 'acct_********************') // id of the connected account 
      //); 

      // echo "<pre>------"; 
      // print_r($token); 
      // echo "-----</pre>"; 

      // ONE COMBINATION. DOES NOT WORK 
      // var_dump($customer_id, $paymentDesc, $destinationAccount); 
      // $charge = \Stripe\Charge::create(array(
      // "amount" => $paymentDesc['total'] * 100, 
      // "currency" => "usd", 
      // "source" => $token, 
      // "description" => $paymentDesc['description'], 
      // 'destination' => $destinationAccount 
      //)); 
      // 
      // 

      // IT WORKS IN THE MAIN ACCOUNT BUT IT IS NOT OUR GOAL, BUT WE CAN TRANSFER THE MONEY TO ANOTHER CONNECTED ACCOUNT 
      // $charge = \Stripe\Charge::create(array(
      // 'amount' => $paymentDesc['total'] * 100, 
      // 'currency' => 'usd', 
      // 'customer' => $customer_id, 
      // "description" => $paymentDesc['description'] 
      //)); 

      // ANOTHER COMBINATION. DOES NOT WORK 
      /*$charge = \Stripe\Charge::create(array(
       'amount' => $paymentDesc['total'] * 100, 
       'currency' => 'usd', 
       "description" => $paymentDesc['description'], 
       'customer' => $customer_id 
      ), array('stripe_account' => 'acct_************'));*/ 

      // ANOTHER COMBINATION. DOES NOT WORK 
      /*$charge = \Stripe\Charge::create(array(
       'amount' => $paymentDesc['total'] * 100, 
       'currency' => 'usd', 
       "description" => $paymentDesc['description'], 
       'customer' => $customer_id 
      ), array('api_key' => 'ACCESS_TOKEN_IN_DB')); 

      echo "<pre>------"; 
      print_r($charge); 
      echo "-----</pre>"; 

      return array('charge' => $charge);*/ 

     } catch(Stripe_CardError $e) { 
      $errors = array('error' => false, 'message' => 'Card was declined.', 'e' => $e); 
     } catch (Stripe_InvalidRequestError $e) { 
      $errors = array('error' => false, 'message' => 'Invalid parameters were supplied to Stripe\'s API', 'e' => $e); 
     } catch (Stripe_AuthenticationError $e) { 
      $errors = array('error' => false, 'message' => 'Authentication with Stripe\'s API failed!', 'e' => $e); 
     } catch (Stripe_ApiConnectionError $e) { 
      $errors = array('error' => false, 'message' => 'Network communication with Stripe failed', 'e' => $e); 
     } catch (Stripe_Error $e) { 
      $errors = array('error' => false, 'message' => 'Stripe error. Something wrong just happened!', 'e' => $e); 
     } catch (Exception $e) { 
      $errors = array('error' => false, 'message' => 'An error has ocurred getting info customer.', 'e' => $e); 
     } 

     return $errors; 
    } 

答えて

0

あなたがaccess_tokenrefresh_token、唯一stripe_user_id含む接続アカウントを保存する必要はありません:すべてのコメントは、私たちがしようと別のテストされていますConnectで作業するにはIDが必要です。

プラットフォームの秘密APIキーをすべてのリクエストに使用し、共有顧客のドキュメントに示されているように、接続されたアカウントIDをStripeアカウントのヘッダーに渡すことができます。あなたがしたいあなたの場合

https://stripe.com/docs/connect/authentication#authentication-via-the-stripe-account-header

// Create a Token from the existing customer on the platform's account 
$sharedToken = \Stripe\Token::create(
    array("customer" => CUSTOMER_ID, "card" => CARD_ID), 
    array("stripe_account" => CONNECTED_STRIPE_ACCOUNT_ID) // id of the connected account 
); 

$sharedCustomer = \Stripe\Customer::create(array(
    "description" => "Customer for [email protected]", 
    "source" => $sharedToken), 
    array("stripe_account" => CONNECTED_STRIPE_ACCOUNT_ID) 
); 

あなたはその後、作成することができ、より一般的にこのヘッダは、それが接続されているアカウントに向けたのは、ほぼすべてのAPIリクエストに追加することができますこの共有された顧客から同じ方法で請求してください。

\Stripe\Charge::create(array(
    "amount" => 2000, 
    "currency" => "usd", 
    "customer" => $sharedCustomer), 
    array("stripe_account" => CONNECTED_STRIPE_ACCOUNT_ID) 
); 
+0

ありがとうございます@Spiff。私はドキュメンテーションをたくさん読んでいるのに多くの時間を費やし、私はそれを全く理解しませんでした。私が気付く別の問題は、メニューのConnected Accountsにあります。Connected B and C accountsはメインアカウントに接続されていません。しかしメインアカウントはBアカウントとCアカウントに接続されていました。その後、私はそれらのアカウントを接続する別のプロセスを作成し、それは動作します。再び、ありがとう。 –

+0

よろしくお願いします!接続アカウントリストには子供アカウントしか表示されませんが、プラットフォームは表示されませんが、接続が壊れているわけではありません。あなたのアカウントが接続されている各プラットフォームを確認するには、アカウント設定を確認する必要があります。https://dashboard.stripe.com/account/applications – Spiff

関連する問題