$userAgentString ); $response = wp_remote_get($request, $args); if ( is_wp_error( $response ) || $response['response']['code'] !== 200) { throw new \Exception( 'Could not reach blockchain.info.' ); } $totalReceived = (float) json_decode($response['body'])->total_received; error_log('address ' . $address . ' has total funds of: ' . $totalReceived); return $totalReceived > 0; } public static function check_address_for_payment($address, $orderAmount,$requiredConfirmations) { $userAgentString = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.12 (KHTML, like Gecko) Chrome/9.0.576.0 Safari/534.12'; $request = 'https://blockchain.info/q/getreceivedbyaddress/' . $address. '?confirmations=' . $requiredConfirmations; $args = array( 'user-agent' => $userAgentString ); $response = wp_remote_get($request, $args); if ( is_wp_error( $response ) || $response['response']['code'] !== 200) { throw new \Exception( 'Could not reach blockchain.info.' ); } //error_log(print_r($response, true)); $totalReceivedSatoshi = (float) json_decode($response['body']); $totalReceived = $totalReceivedSatoshi / 100000000; $repo = new AGC_MPK_Repo('BTC', ''); $repo->set_address_total_received($address, $totalReceived); $amountToVerify = ((float) $orderAmount) * 0.97; error_log('checking ' . $address . ' for payment amount of '. $amountToVerify . '... total received is ' . $totalReceived); return $totalReceived > $amountToVerify; } } ?>