BraintreeSettlementBatchSummaryGateway

The PayPal for WooCommerce Braintree SettlementBatchSummaryGateway class.

Defined (1)

The class is defined in the following location(s).

/classes/lib/Braintree/Braintree/SettlementBatchSummaryGateway.php  
  1. class SettlementBatchSummaryGateway 
  2. /** 
  3. * @var Gateway 
  4. */ 
  5. private $_gateway; 
  6.  
  7. /** 
  8. * @var Configuration 
  9. */ 
  10. private $_config; 
  11.  
  12. /** 
  13. * @var Http 
  14. */ 
  15. private $_http; 
  16.  
  17. /** 
  18. * @param Gateway $gateway 
  19. */ 
  20. public function __construct($gateway) 
  21. $this->_gateway = $gateway; 
  22. $this->_config = $gateway->config; 
  23. $this->_config->assertHasAccessTokenOrKeys(); 
  24. $this->_http = new Http($gateway->config); 
  25.  
  26. /** 
  27. * @param string $settlement_date 
  28. * @param string $groupByCustomField 
  29. * @return SettlementBatchSummary|Result\Error 
  30. */ 
  31. public function generate($settlement_date, $groupByCustomField = NULL) 
  32. $criteria = ['settlement_date' => $settlement_date]; 
  33. if (isset($groupByCustomField)) 
  34. $criteria['group_by_custom_field'] = $groupByCustomField; 
  35. $params = ['settlement_batch_summary' => $criteria]; 
  36. $path = $this->_config->merchantPath() . '/settlement_batch_summary'; 
  37. $response = $this->_http->post($path, $params); 
  38.  
  39. if (isset($groupByCustomField)) 
  40. $response['settlementBatchSummary']['records'] = $this->_underscoreCustomField( 
  41. $groupByCustomField,  
  42. $response['settlementBatchSummary']['records'] 
  43. ); 
  44.  
  45. return $this->_verifyGatewayResponse($response); 
  46.  
  47. /** 
  48. * @param string $groupByCustomField 
  49. * @param array $records 
  50. * @return array 
  51. */ 
  52. private function _underscoreCustomField($groupByCustomField, $records) 
  53. $updatedRecords = []; 
  54.  
  55. foreach ($records as $record) 
  56. $camelized = Util::delimiterToCamelCase($groupByCustomField); 
  57. $record[$groupByCustomField] = $record[$camelized]; 
  58. unset($record[$camelized]); 
  59. $updatedRecords[] = $record; 
  60.  
  61. return $updatedRecords; 
  62.  
  63. /** 
  64. * @param array $response 
  65. * @return Result\Successful|Result\Error 
  66. * @throws Exception\Unexpected 
  67. */ 
  68. private function _verifyGatewayResponse($response) 
  69. if (isset($response['settlementBatchSummary'])) { 
  70. return new Result\Successful( 
  71. SettlementBatchSummary::factory($response['settlementBatchSummary']) 
  72. ); 
  73. } else if (isset($response['apiErrorResponse'])) { 
  74. return new Result\Error($response['apiErrorResponse']); 
  75. } else { 
  76. throw new Exception\Unexpected( 
  77. "Expected settlementBatchSummary or apiErrorResponse" 
  78. );