apiUser = $apiUser; $this->apiPassword = $apiPassword; $this->apiSignature = $apiSignature; $this->apiEndPoint = $apiEndPoint; } public function doMassPay(WPAM_PayPal_MassPayRequest $request) { $response = $this->executeRequest('MassPay', $request->getFields()); return $response; } private function executeRequest($method, array $fields) { $currency = WPAM_MoneyHelper::getCurrencyCode(); $fields = array_merge( $fields, array( 'USER' => $this->apiUser, 'PWD' => $this->apiPassword, 'VERSION' => '65.0', 'SIGNATURE' => $this->apiSignature, 'METHOD' => $method, 'CURRENCYCODE' => $currency ) ); WPAM_Logger::log_debug('PayPal MassPay post data:'); WPAM_Logger::log_debug_array($fields); $postData = http_build_query($fields, NULL, '&'); $response = $this->executePayPalRequest($postData); WPAM_Logger::log_debug('PayPal MassPay response:'); WPAM_Logger::log_debug_array($response); return new WPAM_PayPal_Response($response); } private function executePayPalRequest( $postData ) { $args = array( 'body' => $postData, 'sslverify' => false, ); $response = wp_remote_post( $this->apiEndPoint, $args ); if ( is_wp_error( $response ) ) { throw new WPAM_PayPal_ServiceException( sprintf( __( "POST failed\nerrors:\n%serrordata:\n%s", 'affiliates-manager' ), print_r($response->errors, true), print_r($response->error_data, true) ) ); } elseif ( isset( $response['response']['code'] ) && $response['response']['code'] == 200 ) { return $response['body']; } throw new WPAM_PayPal_ServiceException( sprintf( __( 'Unknown response: %s', 'affiliates-manager' ), print_r( $response, true ) ) ); } }