本文整理汇总了PHP中Braintree_Util类的典型用法代码示例。如果您正苦于以下问题:PHP Braintree_Util类的具体用法?PHP Braintree_Util怎么用?PHP Braintree_Util使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Braintree_Util类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: all
public function all()
{
$path = $this->_config->merchantPath() . '/discounts';
$response = $this->_http->get($path);
$discounts = array("discount" => $response['discounts']);
return Braintree_Util::extractAttributeAsArray($discounts, 'discount');
}
示例2: _initializeFromArray
/**
* initializes instance properties from the keys/values of an array
* @ignore
* @access protected
* @param array $attributes array of properties to set - single level
* @return none
*/
private function _initializeFromArray($attributes)
{
foreach ($attributes as $name => $value) {
$varName = "_{$name}";
$this->{$varName} = Braintree_Util::delimiterToCamelCase($value, '_');
}
}
示例3: all
public function all()
{
$path = $this->_config->merchantPath() . '/add_ons';
$response = $this->_http->get($path);
$addOns = array("addOn" => $response['addOns']);
return Braintree_Util::extractAttributeAsArray($addOns, 'addOn');
}
示例4: _createElementsFromArray
/**
* Construct XML elements with attributes from an associative array.
*
* @access protected
* @static
* @param object $writer XMLWriter object
* @param array $aData contains attributes and values
* @return none
*/
private static function _createElementsFromArray(&$writer, $aData)
{
if (!is_array($aData)) {
$writer->text($aData);
return;
}
foreach ($aData as $index => $element) {
// convert the style back to gateway format
$elementName = Braintree_Util::camelCaseToDelimiter($index, '-');
// handle child elements
$writer->startElement($elementName);
if (is_array($element)) {
if (array_key_exists(0, $element) || empty($element)) {
$writer->writeAttribute('type', 'array');
foreach ($element as $ignored => $itemInArray) {
$writer->startElement('item');
self::_createElementsFromArray($writer, $itemInArray);
$writer->endElement();
}
} else {
self::_createElementsFromArray($writer, $element);
}
} else {
// generate attributes as needed
$attribute = self::_generateXmlAttribute($element);
if (is_array($attribute)) {
$writer->writeAttribute($attribute[0], $attribute[1]);
$element = $attribute[2];
}
$writer->text($element);
}
$writer->endElement();
}
}
示例5: arrayFromXml
/**
* Converts an XML string into a multidimensional array
*
* @param string $xml
* @return array
*/
public static function arrayFromXml($xml)
{
$document = new DOMDocument('1.0', 'UTF-8');
$document->loadXML($xml);
$root = $document->documentElement->nodeName;
return Braintree_Util::delimiterToCamelCaseArray(array($root => self::_nodeToValue($document->childNodes->item(0))));
}
示例6: update
public function update($subscriptionId, $attributes)
{
Braintree_Util::verifyKeys(self::_updateSignature(), $attributes);
$path = $this->_config->merchantPath() . '/subscriptions/' . $subscriptionId;
$response = $this->_http->put($path, array('subscription' => $attributes));
return $this->_verifyGatewayResponse($response);
}
示例7: connectUrl
public function connectUrl($params = array())
{
$query = Braintree_Util::camelCaseToDelimiterArray($params, '_');
$query['client_id'] = $this->_config->getClientId();
$url = $this->_config->baseUrl() . '/oauth/connect?' . http_build_query($query);
return $this->signUrl($url);
}
示例8: conditionallyVerifyKeys
public function conditionallyVerifyKeys($params)
{
if (array_key_exists("customerId", $params)) {
Braintree_Util::verifyKeys($this->generateWithCustomerIdSignature(), $params);
} else {
Braintree_Util::verifyKeys($this->generateWithoutCustomerIdSignature(), $params);
}
}
示例9: connectUrl
public function connectUrl($params = array())
{
$query = Braintree_Util::camelCaseToDelimiterArray($params, '_');
$query['client_id'] = $this->_config->getClientId();
$queryString = preg_replace('/\\%5B\\d+\\%5D/', '%5B%5D', http_build_query($query));
$url = $this->_config->baseUrl() . '/oauth/connect?' . $queryString;
return $this->signUrl($url);
}
示例10: _iteratorToArray
/**
* processes SimpleXMLIterator objects recursively
*
* @access protected
* @param object $iterator
* @return array xml converted to array
*/
private static function _iteratorToArray($iterator)
{
$xmlArray = array();
$value = null;
// rewind the iterator and check if the position is valid
// if not, return the string it contains
$iterator->rewind();
if (!$iterator->valid()) {
return self::_typecastXmlValue($iterator);
}
for ($iterator->rewind(); $iterator->valid(); $iterator->next()) {
$tmpArray = null;
$value = null;
// get the attribute type string for use in conditions below
$attributeType = $iterator->attributes()->type;
// extract the parent element via xpath query
$parentElement = $iterator->xpath($iterator->key() . '/..');
if ($parentElement[0] instanceof SimpleXMLIterator) {
$parentElement = $parentElement[0];
$parentKey = Braintree_Util::delimiterToCamelCase($parentElement->getName());
} else {
$parentElement = null;
}
if ($parentKey == "customFields") {
$key = Braintree_Util::delimiterToUnderscore($iterator->key());
} else {
$key = Braintree_Util::delimiterToCamelCase($iterator->key());
}
// process children recursively
if ($iterator->hasChildren()) {
// return the child elements
$value = self::_iteratorToArray($iterator->current());
// if the element is an array type,
// use numeric keys to allow multiple values
if ($attributeType != 'array') {
$tmpArray[$key] = $value;
}
} else {
// cast values according to attributes
$tmpArray[$key] = self::_typecastXmlValue($iterator->current());
}
// set the output string
$output = isset($value) ? $value : $tmpArray[$key];
// determine if there are multiple tags of this name at the same level
if (isset($parentElement) && $parentElement->attributes()->type == 'collection' && $iterator->hasChildren()) {
$xmlArray[$key][] = $output;
continue;
}
// if the element was an array type, output to a numbered key
// otherwise, use the element name
if ($attributeType == 'array') {
$xmlArray[] = $output;
} else {
$xmlArray[$key] = $output;
}
}
return $xmlArray;
}
示例11: __toString
public function __toString()
{
$display = array('amount', 'reason', 'status', 'replyByDate', 'receivedDate', 'currencyIsoCode');
$displayAttributes = array();
foreach ($display as $attrib) {
$displayAttributes[$attrib] = $this->{$attrib};
}
return __CLASS__ . '[' . Braintree_Util::attributesToString($displayAttributes) . ']';
}
示例12: __toString
public function __toString()
{
$display = array('id', 'merchantAccountDetails', 'exceptionMessage', 'amount', 'disbursementDate', 'followUpAction', 'retry', 'success', 'transactionIds');
$displayAttributes = array();
foreach ($display as $attrib) {
$displayAttributes[$attrib] = $this->{$attrib};
}
return __CLASS__ . '[' . Braintree_Util::attributesToString($displayAttributes) . ']';
}
示例13: returnObjectOrThrowException
/**
*
* @param string $className
* @param object $resultObj
* @return object returns the passed object if successful
* @throws Braintree_Exception_ValidationsFailed
*/
public static function returnObjectOrThrowException($className, $resultObj)
{
$resultObjName = Braintree_Util::cleanClassName($className);
if ($resultObj->success) {
return $resultObj->{$resultObjName};
} else {
throw new Braintree_Exception_ValidationsFailed();
}
}
示例14: fetch
public static function fetch($query, $ids)
{
$criteria = array();
foreach ($query as $term) {
$criteria[$term->name] = $term->toparam();
}
$criteria["ids"] = Braintree_CreditCardVerificationSearch::ids()->in($ids)->toparam();
$response = Braintree_Http::post('/verifications/advanced_search', array('search' => $criteria));
return Braintree_Util::extractattributeasarray($response['creditCardVerifications'], 'verification');
}
示例15: put
public static function put($path, $params = null)
{
$response = self::_doRequest('PUT', $path, self::_buildXml($params));
$responseCode = $response['status'];
if ($responseCode === 200 || $responseCode === 201 || $responseCode === 422) {
return Braintree_Xml::buildArrayFromXml($response['body']);
} else {
Braintree_Util::throwStatusCodeException($responseCode);
}
}