Skip to content

Commit

Permalink
Merge pull request #708 from stripe/ob-nested-error-msgs
Browse files Browse the repository at this point in the history
Update error messages for nested resource operations
  • Loading branch information
ob-stripe authored Aug 23, 2019
2 parents 7137501 + 81da9f7 commit 2fb84f0
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 32 deletions.
10 changes: 6 additions & 4 deletions lib/AlipayAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ public function instanceUrl()
*/
public static function retrieve($_id, $_opts = null)
{
$msg = "Alipay accounts cannot be accessed without a customer ID. " .
"Retrieve an Alipay account using \$customer->sources->retrieve('alipay_account_id') instead.";
$msg = "Alipay accounts cannot be retrieved without a customer ID. " .
"Retrieve an Alipay account using `Customer::retrieveSource(" .
"'customer_id', 'alipay_account_id')`.";
throw new Error\InvalidRequest($msg, null);
}

Expand All @@ -64,8 +65,9 @@ public static function retrieve($_id, $_opts = null)
*/
public static function update($_id, $_params = null, $_options = null)
{
$msg = "Alipay accounts cannot be accessed without a customer ID. " .
"Call save() on \$customer->sources->retrieve('alipay_account_id') instead.";
$msg = "Alipay accounts cannot be updated without a customer ID. " .
"Update an Alipay account using `Customer::updateSource(" .
"'customer_id', 'alipay_account_id', \$updateParams)`.";
throw new Error\InvalidRequest($msg, null);
}
}
16 changes: 10 additions & 6 deletions lib/BankAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ public function instanceUrl()
*/
public static function retrieve($_id, $_opts = null)
{
$msg = "Bank accounts cannot be accessed without a customer ID or account ID. " .
"Retrieve a bank account using \$customer->sources->retrieve('bank_account_id') or " .
"\$account->external_accounts->retrieve('bank_account_id') instead.";
$msg = "Bank accounts cannot be retrieved without a customer ID or " .
"an account ID. Retrieve a bank account using " .
"`Customer::retrieveSource('customer_id', " .
"'bank_account_id')` or `Account::retrieveExternalAccount(" .
"'account_id', 'bank_account_id')`.";
throw new Error\InvalidRequest($msg, null);
}

Expand All @@ -86,9 +88,11 @@ public static function retrieve($_id, $_opts = null)
*/
public static function update($_id, $_params = null, $_options = null)
{
$msg = "Bank accounts cannot be accessed without a customer ID or account ID. " .
"Call save() on \$customer->sources->retrieve('bank_account_id') or " .
"\$account->external_accounts->retrieve('bank_account_id') instead.";
$msg = "Bank accounts cannot be updated without a customer ID or an " .
"account ID. Update a bank account using " .
"`Customer::updateSource('customer_id', 'bank_account_id', " .
"\$updateParams)` or `Account::updateExternalAccount(" .
"'account_id', 'bank_account_id', \$updateParams)`.";
throw new Error\InvalidRequest($msg, null);
}

Expand Down
10 changes: 6 additions & 4 deletions lib/Capability.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ public function instanceUrl()
*/
public static function retrieve($_id, $_opts = null)
{
$msg = "Capabilities cannot be accessed without an account ID. " .
"Retrieve a Capability using \$account->retrieveCapability('acap_123') instead.";
$msg = "Capabilities cannot be retrieved without an account ID. " .
"Retrieve a capability using `Account::retrieveCapability(" .
"'account_id', 'capability_id')`.";
throw new Error\InvalidRequest($msg, null);
}

Expand All @@ -75,8 +76,9 @@ public static function retrieve($_id, $_opts = null)
*/
public static function update($_id, $_params = null, $_options = null)
{
$msg = "Capabilities cannot be accessed without an account ID. " .
"Update a Capability using \$account->updateCapability('acap_123') instead.";
$msg = "Capabilities cannot be updated without an account ID. " .
"Update a capability using `Account::updateCapability(" .
"'account_id', 'capability_id', \$updateParams)`.";
throw new Error\InvalidRequest($msg, null);
}
}
17 changes: 9 additions & 8 deletions lib/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ public function instanceUrl()
*/
public static function retrieve($_id, $_opts = null)
{
$msg = "Cards cannot be accessed without a customer, recipient or account ID. " .
"Retrieve a card using \$customer->sources->retrieve('card_id'), " .
"\$recipient->cards->retrieve('card_id'), or " .
"\$account->external_accounts->retrieve('card_id') instead.";
$msg = "Cards cannot be retrieved without a customer ID or an " .
"account ID. Retrieve a card using " .
"`Customer::retrieveSource('customer_id', 'card_id')` or " .
"`Account::retrieveExternalAccount('account_id', 'card_id')`.";
throw new Error\InvalidRequest($msg, null);
}

Expand All @@ -120,10 +120,11 @@ public static function retrieve($_id, $_opts = null)
*/
public static function update($_id, $_params = null, $_options = null)
{
$msg = "Cards cannot be accessed without a customer, recipient or account ID. " .
"Call save() on \$customer->sources->retrieve('card_id'), " .
"\$recipient->cards->retrieve('card_id'), or " .
"\$account->external_accounts->retrieve('card_id') instead.";
$msg = "Cards cannot be updated without a customer ID or an " .
"account ID. Update a card using " .
"`Customer::updateSource('customer_id', 'card_id', " .
"\$updateParams)` or `Account::updateExternalAccount(" .
"'account_id', 'card_id', \$updateParams)`.";
throw new Error\InvalidRequest($msg, null);
}
}
12 changes: 8 additions & 4 deletions lib/CustomerBalanceTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ public function instanceUrl()
*/
public static function retrieve($_id, $_opts = null)
{
$msg = "Customer Balance Transactions cannot be accessed without a customer ID. " .
"Retrieve a balance transaction using Customer::retrieveBalanceTransaction('cus_123', 'cbtxn_123') instead.";
$msg = "Customer Balance Transactions cannot be retrieved without a " .
"customer ID. Retrieve a Customer Balance Transaction using " .
"`Customer::retrieveBalanceTransaction('customer_id', " .
"'balance_transaction_id')`.";
throw new Error\InvalidRequest($msg, null);
}

Expand All @@ -81,8 +83,10 @@ public static function retrieve($_id, $_opts = null)
*/
public static function update($_id, $_params = null, $_options = null)
{
$msg = "Customer Balance Transactions cannot be accessed without a customer ID. " .
"Update a balance transaction using Customer::updateBalanceTransaction('cus_123', 'cbtxn_123', \$params) instead.";
$msg = "Customer Balance Transactions cannot be updated without a " .
"customer ID. Update a Customer Balance Transaction using " .
"`Customer::updateBalanceTransaction('customer_id', " .
"'balance_transaction_id', \$updateParams)`.";
throw new Error\InvalidRequest($msg, null);
}
}
10 changes: 6 additions & 4 deletions lib/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ public function instanceUrl()
*/
public static function retrieve($_id, $_opts = null)
{
$msg = "Persons cannot be accessed without an account ID. " .
"Retrieve a Person using \$account->retrievePerson('person_id') instead.";
$msg = "Persons cannot be retrieved without an account ID. Retrieve " .
"a person using `Account::retrievePerson('account_id', " .
"'person_id')`.";
throw new Error\InvalidRequest($msg, null);
}

Expand All @@ -100,8 +101,9 @@ public static function retrieve($_id, $_opts = null)
*/
public static function update($_id, $_params = null, $_options = null)
{
$msg = "Persons cannot be accessed without an account ID. " .
"Retrieve a Person using \$account->retrievePerson('person_id') instead.";
$msg = "Persons cannot be updated without an account ID. Update " .
"a person using `Account::updatePerson('account_id', " .
"'person_id', \$updateParams)`.";
throw new Error\InvalidRequest($msg, null);
}
}
5 changes: 3 additions & 2 deletions lib/TaxId.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ public function instanceUrl()
*/
public static function retrieve($_id, $_opts = null)
{
$msg = "Tax Ids cannot be accessed without a customer ID. " .
"Retrieve a Tax Id using Customer::retrieveTaxId('tax_id') instead.";
$msg = "Tax IDs cannot be retrieved without a customer ID. Retrieve " .
"a tax ID using `Customer::retrieveTaxId('customer_id', " .
"'tax_id_id')`.";
throw new Error\InvalidRequest($msg, null);
}
}

0 comments on commit 2fb84f0

Please sign in to comment.