/** * @return null|string The instance URL for this resource. It needs to be special * cased because it doesn't fit into the standard resource pattern. * * @throws Error\InvalidRequest */ public function instanceUrl() { $id = $this['id']; if (!$id) { $class = get_class($this); $msg = "Could not determine which URL to request: {$class} instance " . "has invalid ID: {$id}"; throw new Error\InvalidRequest($msg, null); } if ($this['customer']) { $parent = $this['customer']; $base = Customer::classUrl(); $path = 'sources'; } elseif ($this['account']) { $parent = $this['account']; $base = Account::classUrl(); $path = 'external_accounts'; } elseif ($this['recipient']) { $parent = $this['recipient']; $base = Recipient::classUrl(); $path = 'cards'; } else { return; } $parent = Util\Util::utf8($parent); $id = Util\Util::utf8($id); $parentExtn = urlencode($parent); $extn = urlencode($id); return "{$base}/{$parentExtn}/{$path}/{$extn}"; }
public function testVerify() { self::authorizeFromEnv(); $bankAccountToken = Token::create(array('bank_account' => array('country' => 'US', 'routing_number' => '110000000', 'account_number' => '000123456789', 'name' => 'Jane Austen', 'account_holder_type' => 'company'))); $customer = Customer::create(); $externalAccount = $customer->sources->create(array('bank_account' => $bankAccountToken->id)); $verifiedAccount = $externalAccount->verify(array('amounts' => array(32, 45)), null); $base = Customer::classUrl(); $parentExtn = $externalAccount['customer']; $extn = $externalAccount['id']; $this->assertEquals("{$base}/{$parentExtn}/sources/{$extn}", $externalAccount->instanceUrl()); }
/** * @return string The API URL for this Stripe subscription. */ public function instanceUrl() { $id = $this['id']; $customer = $this['customer']; if (!$id) { throw new Error\InvalidRequest("Could not determine which URL to request: " . "class instance has invalid ID: {$id}", null); } $id = Util\Util::utf8($id); $customer = Util\Util::utf8($customer); $base = Customer::classUrl(); $customerExtn = urlencode($customer); $extn = urlencode($id); return "{$base}/{$customerExtn}/subscriptions/{$extn}"; }
public function testUpdateWithCustomer() { self::authorizeFromEnv(); $receiver = $this->createTestBitcoinReceiver("*****@*****.**"); $customer = Customer::create(array("source" => $receiver->id)); $receiver = BitcoinReceiver::retrieve($receiver->id); $receiver->description = "a new description"; $receiver->save(); $base = Customer::classUrl(); $parentExtn = $receiver['customer']; $extn = $receiver['id']; $this->assertEquals("{$base}/{$parentExtn}/sources/{$extn}", $receiver->instanceUrl()); $updatedReceiver = BitcoinReceiver::retrieve($receiver->id); $this->assertEquals($receiver["description"], $updatedReceiver["description"]); }
/** * @return string The instance URL for this resource. It needs to be special * cased because it doesn't fit into the standard resource pattern. */ public function instanceUrl() { $id = $this['id']; if (!$id) { $class = get_class($this); $msg = "Could not determine which URL to request: {$class} instance " . "has invalid ID: {$id}"; throw new Error\InvalidRequest($msg, null); } $id = ApiRequestor::utf8($id); $extn = urlencode($id); if (!$this['customer']) { $base = BitcoinReceiver::classUrl(); return "{$base}/{$extn}"; } else { $base = Customer::classUrl(); $parent = ApiRequestor::utf8($this['customer']); $parentExtn = urlencode($parent); return "{$base}/{$parentExtn}/sources/{$extn}"; } }
/** * @return string The instance URL for this resource. It needs to be special * cased because it doesn't fit into the standard resource pattern. */ public function instanceUrl() { $id = $this['id']; if (!$id) { $class = get_class($this); $msg = "Could not determine which URL to request: {$class} instance " . "has invalid ID: {$id}"; throw new Error\InvalidRequest($msg, null); } if (isset($this['customer'])) { $parent = $this['customer']; $base = Customer::classUrl(); } elseif (isset($this['recipient'])) { $parent = $this['recipient']; $base = Recipient::classUrl(); } else { return null; } $parent = ApiRequestor::utf8($parent); $id = ApiRequestor::utf8($id); $parentExtn = urlencode($parent); $extn = urlencode($id); return "{$base}/{$parentExtn}/cards/{$extn}"; }