protected function ping($url, $port = 80, $timeout = 6) { $host = parse_url($url, PHP_URL_HOST); $fsock = fsockopen($host, $port, $errno, $errstr, $timeout); if (!$fsock) { Log::log('Ping for ' . $host . ':' . $port . ' (timeout=' . $timeout . ') failed'); return false; } else { return true; } }
public function publish() { $tweet = $this->getTitle(); if ($url = $this->getUrl()) { $tweet = substr($tweet, 0, 140 - strlen($url) - 5) . '... ' . $url; } while ($curlength = iconv_strlen(htmlspecialchars($tweet, ENT_QUOTES, 'UTF-8'), 'UTF-8') >= 140) { $tweet = substr($tweet, 0, -1); } try { $response = $this->_twitter->post('statuses/update', array('status' => $tweet)); } catch (Exception $e) { AjdeLog::log($response); AjdeExceptionLog::logException($e); return false; } if ($response->user && $response->user->id && $response->id_str) { return sprintf("http://twitter.com/%s/status/%s", $response->user->id, $response->id_str); } else { return false; } }
public function updatePayment() { // PHP 4.1 // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&{$key}={$value}"; } // post back to PayPal system to validate $header = ''; $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; $fp = fsockopen($this->isSandbox() ? 'ssl://www.sandbox.paypal.com' : 'ssl://www.paypal.com', 443, $errno, $errstr, 30); // assign posted variables to local variables $item_name = issetor($_POST['item_name']); $item_number = issetor($_POST['item_number']); $payment_status = issetor($_POST['payment_status']); $payment_amount = issetor($_POST['mc_gross']); $payment_currency = issetor($_POST['mc_currency']); $txn_id = issetor($_POST['txn_id']); $receiver_email = issetor($_POST['receiver_email']); $payer_email = issetor($_POST['payer_email']); Model::register('shop'); $secret = issetor($_POST['custom']); $transaction = new TransactionModel(); $changed = false; if (!$fp) { // HTTP ERROR } else { fputs($fp, $header . $req); while (!feof($fp)) { $res = fgets($fp, 1024); if (strcmp($res, "VERIFIED") == 0) { if (!$transaction->loadByField('secret', $secret)) { Log::log('Could not find transaction for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret); return array('success' => false, 'transaction' => null); } // check the payment_status is Completed // accept Pending from PayPal (eChecks?) $acceptPending = true; if ($payment_status == 'Completed' || $acceptPending && $payment_status == 'Pending') { $details = 'AMOUNT: ' . $payment_amount . PHP_EOL . 'CURRENCY: ' . $payment_currency . PHP_EOL . 'PAYER_EMAIL: ' . $payer_email . PHP_EOL . 'RECEIVER_EMAIL: ' . $receiver_email . PHP_EOL . 'TXN_ID: ' . $txn_id . PHP_EOL; // update transaction only once if ($transaction->payment_status != 'completed') { $transaction->payment_details = $details; $transaction->payment_status = 'completed'; $transaction->save(); $changed = true; } // Write pending to Log if ($payment_status == 'Pending') { Log::log('Status is Pending but accepting now. PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret); } return array('success' => true, 'changed' => $changed, 'transaction' => $transaction); } else { if ($transaction->payment_status != 'refused') { $transaction->payment_status = 'refused'; $transaction->save(); $changed = true; } Log::log('Status is not Completed but ' . $payment_status . ' for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret); } // check that txn_id has not been previously processed // check that receiver_email is your Primary PayPal email // check that payment_amount/payment_currency are correct // process payment } else { if (strcmp($res, "INVALID") == 0) { if (!$transaction->loadByField('secret', $secret)) { // secret not found anyway $transaction = null; Log::log('Could not find transaction for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret); } else { // log for manual investigation if ($transaction->payment_status != 'refused') { $transaction->payment_status = 'refused'; $transaction->save(); $changed = true; } Log::log('Validation failed for PayPal payment with txn id ' . $txn_id); } } } } fclose($fp); } return array('success' => false, 'changed' => $changed, 'transaction' => $transaction); }
public function updatePayment() { $payment = false; $mollie = new Client(); $mollie->setApiKey($this->getApiKey()); $transaction = new TransactionModel(); $changed = false; // see if we are here for the webhook or user return url $mollie_id = Ajde::app()->getRequest()->getPostParam('id', false); // from webhook $order_id = Ajde::app()->getRequest()->getParam('order_id', false); // from user request if (!$mollie_id && $order_id) { // load from order_id $transaction->loadByField('secret', $order_id); $mollie_id = $transaction->payment_providerid; try { $payment = $mollie->payments->get($mollie_id); } catch (Exception $e) { AjdeExceptionLog::logException($e); $payment = false; } } else { if ($mollie_id) { // laod from mollie transaction id try { $payment = $mollie->payments->get($mollie_id); $order_id = $payment->metadata->order_id; $transaction->loadByField('secret', $order_id); } catch (Exception $e) { AjdeExceptionLog::logException($e); $payment = false; } } } if (!$payment || !$mollie_id || !$order_id || !$transaction->hasLoaded()) { AjdeLog::log('Could not find transaction for Mollie payment for mollie id ' . $mollie_id . ' and transaction secret ' . $order_id); return array('success' => false, 'changed' => $changed, 'transaction' => $transaction); } // what to return? $paid = false; $payment_details = $payment->details; if (is_object($payment_details) || is_array($payment_details)) { $payment_details = json_encode($payment_details); } // save details $details = 'PAYMENT STATUS: ' . (string) $payment->status . PHP_EOL . 'PAYMENT AMOUNT: ' . (string) $payment->amount . PHP_EOL . 'PAYMENT AT: ' . (string) $payment->paidDatetime . PHP_EOL . 'CANCELLED AT: ' . (string) $payment->cancelledDatetime . PHP_EOL . 'EXPIRED AT: ' . (string) $payment->expiredDatetime . PHP_EOL . 'PAYER DETAILS: ' . (string) $payment_details; $transaction->payment_details = $details; switch ($payment->status) { case "open": if ($transaction->payment_status != 'requested') { $transaction->payment_status = 'requested'; $transaction->save(); $changed = true; } break; case "paidout": case "paid": $paid = true; // update transaction only once if ($transaction->payment_status != 'completed') { $transaction->paid(); $changed = true; } break; case "cancelled": // update transaction only once if ($transaction->payment_status != 'cancelled') { $transaction->payment_status = 'cancelled'; $transaction->save(); $changed = true; } break; case "expired": // update transaction only once if ($transaction->payment_status != 'refused') { $transaction->payment_status = 'refused'; $transaction->save(); $changed = true; } break; } return array('success' => $paid, 'changed' => $changed, 'transaction' => $transaction); }
private function sendRequest($request, $asRaw = false) { if (self::$_debug) { Log::log("INPUT DATA: " . var_export($request, true)); } $xml = self::buildXML($request); $url = fsockopen("ssl://" . self::$_api_url, 443); if ($url === false) { return array('success' => false, 'response' => 'iDeal foutmelding: Kan niet verbinden'); } $data = $xml->saveXML(); $length = strlen($data); if (self::$_debug) { Log::log("REQUEST XML: " . var_export($data, true)); } $post = "GET " . self::$_api_path . " HTTP/1.0\n"; $post .= "Content-Length: {$length}\n"; $post .= "Content-Type: text/xml\n"; $post .= "Connection: Close\n\n"; $post .= "{$data}\n\n"; fputs($url, $post); $response = ''; while (!feof($url)) { $response .= fgets($url, 1024); } fclose($url); if (self::$_debug) { Log::log("RESPONSE DATA: " . var_export($response, true)); } if ($asRaw) { $contentLenght = strpos($response, PHP_EOL . 'Content-Length:') + 1; $nextLine = strpos($response, PHP_EOL, $contentLenght); $result = trim(substr($response, $nextLine)); } else { if (strpos($response, "<?xml") === false) { return array('success' => false, 'response' => "iDeal foutmelding: Ongeldig antwoord"); } $start = strpos($response, '<?xml'); $response = substr($response, $start); $xml = new DOMDocument(); $xml->loadXML($response); $result = simplexml_import_dom($xml); if (self::$_debug) { Log::log("OUTPUT XML: " . var_export($result, true)); } if ($result->error) { return array('success' => false, 'response' => "iDeal foutmelding ({$result->error}): " . self::getError($result->error)); } } return array('success' => true, 'response' => $result); }