public function update($subscriptionId, $attributes)
 {
     Util::verifyKeys(self::_updateSignature(), $attributes);
     $path = $this->_config->merchantPath() . '/subscriptions/' . $subscriptionId;
     $response = $this->_http->put($path, ['subscription' => $attributes]);
     return $this->_verifyGatewayResponse($response);
 }
Example #2
0
 /**
  * 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 Util::delimiterToCamelCaseArray([$root => self::_nodeToValue($document->childNodes->item(0))]);
 }
Example #3
0
 /**
  * initializes instance properties from the keys/values of an array
  * @ignore
  * @access protected
  * @param array $attributes array of properties to set - single level
  * @return void
  */
 private function _initializeFromArray($attributes)
 {
     foreach ($attributes as $name => $value) {
         $varName = "_{$name}";
         $this->{$varName} = Util::delimiterToCamelCase($value, '_');
     }
 }
 /**
  *
  * @param array $params
  * @throws InvalidArgumentException
  */
 public function conditionallyVerifyKeys($params)
 {
     if (array_key_exists("customerId", $params)) {
         Util::verifyKeys($this->generateWithCustomerIdSignature(), $params);
     } else {
         Util::verifyKeys($this->generateWithoutCustomerIdSignature(), $params);
     }
 }
Example #5
0
 public function put($path, $params = null)
 {
     $response = $this->_doRequest('PUT', $path, $this->_buildXml($params));
     $responseCode = $response['status'];
     if ($responseCode === 200 || $responseCode === 201 || $responseCode === 422 || $responseCode == 400) {
         return Xml::buildArrayFromXml($response['body']);
     } else {
         Util::throwStatusCodeException($responseCode);
     }
 }
Example #6
0
 private function _mapPropertyNamesToObjsToReturn($propertyNames, $objsToReturn)
 {
     if (count($objsToReturn) != count($propertyNames)) {
         $propertyNames = [];
         foreach ($objsToReturn as $obj) {
             array_push($propertyNames, Util::cleanClassName(get_class($obj)));
         }
     }
     return array_combine($propertyNames, $objsToReturn);
 }
 /**
  * return errors for the passed html field.
  * For example, $result->errors->onHtmlField("transaction[customer][last_name]")
  *
  * @param string $field
  * @return array
  */
 public function onHtmlField($field)
 {
     $pieces = preg_split("/[\\[\\]]+/", $field, 0, PREG_SPLIT_NO_EMPTY);
     $errors = $this;
     foreach (array_slice($pieces, 0, -1) as $key) {
         $errors = $errors->forKey(Util::delimiterToCamelCase($key));
         if (!isset($errors)) {
             return [];
         }
     }
     $finalKey = Util::delimiterToCamelCase(end($pieces));
     return $errors->onAttribute($finalKey);
 }
Example #8
0
 /**
  * arrays passed to this method should have a single root element
  * with an array as its value
  * @param array $aData the array of data
  * @return string XML string
  */
 public static function arrayToXml($aData)
 {
     $aData = Util::camelCaseToDelimiterArray($aData, '-');
     // set up the XMLWriter
     $writer = new XMLWriter();
     $writer->openMemory();
     $writer->setIndent(true);
     $writer->setIndentString(' ');
     $writer->startDocument('1.0', 'UTF-8');
     // get the root element name
     $aKeys = array_keys($aData);
     $rootElementName = $aKeys[0];
     // open the root element
     $writer->startElement($rootElementName);
     // create the body
     self::_createElementsFromArray($writer, $aData[$rootElementName], $rootElementName);
     // close the root element and document
     $writer->endElement();
     $writer->endDocument();
     // send the output as string
     return $writer->outputMemory();
 }
 public function submitForSettlementNoValidate($transactionId, $amount = null)
 {
     $result = $this->submitForSettlement($transactionId, $amount);
     return Util::returnObjectOrThrowException(__CLASS__, $result);
 }
 /**
  * update an address record, assuming validations will pass
  *
  * if calling this method in context,
  * customerOrId is the 2nd attribute, addressId 3rd.
  * customerOrId & addressId are not sent in object context.
  *
  * @access public
  * @param array $transactionAttribs
  * @param string $customerId
  * @return object Transaction
  * @throws Exception\ValidationsFailed
  * @see Address::update()
  */
 public function updateNoValidate($customerOrId, $addressId, $attributes)
 {
     $result = $this->update($customerOrId, $addressId, $attributes);
     return Util::returnObjectOrThrowException(__CLASS__, $result);
 }
Example #11
0
 public function submitForPartialSettlement($transactionId, $amount, $attribs = [])
 {
     $this->_validateId($transactionId);
     Util::verifyKeys(self::submitForSettlementSignature(), $attribs);
     $attribs['amount'] = $amount;
     $path = $this->_config->merchantPath() . '/transactions/' . $transactionId . '/submit_for_partial_settlement';
     $response = $this->_http->post($path, ['transaction' => $attribs]);
     return $this->_verifyGatewayResponse($response);
 }
 private function _underscoreKeys($array)
 {
     foreach ($array as $key => $value) {
         $newKey = Util::camelCaseToDelimiter($key, '_');
         unset($array[$key]);
         if (is_array($value)) {
             $array[$newKey] = $this->_underscoreKeys($value);
         } else {
             $array[$newKey] = $value;
         }
     }
     return $array;
 }
 /**
  * updates the paypalAccount record
  *
  * if calling this method in context, $token
  * is the 2nd attribute. $token is not sent in object context.
  *
  * @access public
  * @param array $attributes
  * @param string $token (optional)
  * @return Result\Successful or Result\Error
  */
 public function update($token, $attributes)
 {
     Util::verifyKeys(self::updateSignature(), $attributes);
     $this->_validateId($token);
     return $this->_doUpdate('put', '/payment_methods/paypal_account/' . $token, ['paypalAccount' => $attributes]);
 }
Example #14
0
 public function testReturnObject()
 {
     $this->success = true;
     $this->transaction = new stdClass();
     $t = Braintree\Util::returnObjectOrThrowException('Braintree\\Transaction', $this);
     $this->assertInternalType('object', $t);
 }
 /**
  * returns a string representation of the customer
  * @return string
  */
 public function __toString()
 {
     return __CLASS__ . '[' . Util::attributesToString($this->_attributes) . ']';
 }
 /**
  * update a creditcard record, assuming validations will pass
  *
  * if calling this method in context, $token
  * is the 2nd attribute. $token is not sent in object context.
  * returns a CreditCard object on success
  *
  * @access public
  * @param array $attributes
  * @param string $token
  * @return CreditCard
  * @throws Exception\ValidationsFailed
  */
 public function updateNoValidate($token, $attributes)
 {
     $result = $this->update($token, $attributes);
     return Util::returnObjectOrThrowException(__CLASS__, $result);
 }
 public function update($token, $attribs)
 {
     Util::verifyKeys(self::updateSignature(), $attribs);
     return $this->_doUpdate('/payment_methods/any/' . $token, ['payment_method' => $attribs]);
 }
Example #18
0
 /**
  * create a printable representation of the object as:
  * ClassName[property=value, property=value]
  * @ignore
  * @return string
  */
 public function __toString()
 {
     $output = Util::attributesToString($this->_attributes);
     if (isset($this->_creditCardVerification)) {
         $output .= sprintf('%s', $this->_creditCardVerification);
     }
     return __CLASS__ . '[' . $output . ']';
 }
 public function refund($transactionId, $amount_or_options = null)
 {
     self::_validateId($transactionId);
     if (gettype($amount_or_options) == "array") {
         $options = $amount_or_options;
     } else {
         $options = ["amount" => $amount_or_options];
     }
     Util::verifyKeys(self::refundSignature(), $options);
     $params = ['transaction' => $options];
     $path = $this->_config->merchantPath() . '/transactions/' . $transactionId . '/refund';
     $response = $this->_http->post($path, $params);
     return $this->_verifyGatewayResponse($response);
 }