/** * * Call from your notification handler to convert $_POST data to an object containing invoice data * * @param boolean $apiKey * @return mixed $json * @throws Exception $e * */ function bpVerifyNotification($apiKey = false, $network = false) { //function currently not being used global $bpOptions; try { if (!$apiKey) { $apiKey = $bpOptions['apiKey']; } $post = file_get_contents("php://input"); if (!$post) { return 'No post data'; } if (function_exists('json_decode')) { $json = json_decode($post, true); } else { $json = bpJSONdecode($post); } if (is_string($json)) { return $json; } // error if (!array_key_exists('posData', $json)) { return 'no posData'; } if (function_exists('json_decode')) { $posData = json_decode($json['posData'], true); } else { $posData = bpJSONdecode($json['posData']); } if ($bpOptions['verifyPos'] and $posData['hash'] != bpHash(serialize($posData['posData']), $apiKey)) { return 'authentication failed (bad hash)'; } $json['posData'] = $posData['posData']; if (!array_key_exists('id', $json)) { return 'Cannot find invoice ID'; } return bpGetInvoice($json['id'], $apiKey, $network); } catch (Exception $e) { if ($bpOptions['useLogging']) { bpLog('Error: ' . $e->getMessage()); } return array('error' => $e->getMessage()); } }
function bpVerifyNotification($apiKey = false) { global $bpOptions; if (!$apiKey) { $apiKey = $bpOptions['apiKey']; } $post = file_get_contents("php://input"); if (!$post) { return 'No post data'; } $json = json_decode($post, true); if (is_string($json)) { return $json; } // error if (!array_key_exists('posData', $json)) { return 'no posData'; } $posData = json_decode($json['posData'], true); if ($bpOptions['verifyPos'] and $posData['hash'] != bpHash(serialize($posData['posData']), $apiKey)) { return 'authentication failed (bad hash)'; } $json['posData'] = $posData['posData']; return $json; }
function handle_bitpay_return() { try { $post = file_get_contents("php://input"); if (!$post) { return 'No post data'; } $response = json_decode($post, true); if (is_string($response)) { return $response; } // error if (!array_key_exists('posData', $response)) { return 'No posData'; } $posData = json_decode($response['posData'], true); if ($bpOptions['verifyPos'] and $posData['hash'] != bpHash(serialize($posData['posData']), $bpOptions['apiKey'])) { return 'Authentication failed (bad hash)'; } $response['posData'] = $posData['posData']; } catch (Exception $e) { if ($bpOptions['useLogging']) { bpLog('Error: ' . $e->getMessage()); } return array('error' => $e->getMessage()); } if (isset($response['status'])) { switch ($response['status']) { case 'new': // invoice just created, skip break; case 'paid': case 'complete': case 'confirmed': // payment has been paid, confirmed or marked complete $note = 'Payment ' . $response['status'] . '! BitPay Invoice ID: ' . $response['id']; $amount = $response['price']; $currency = $response['currency']; list($timestamp, $user_id, $sub_id, $key) = explode(':', $response['posData']); // // Update to work with latest 3.5.x Membership version // // and keep backward compatibility with older versions as well // if (!class_exists('Membership_Gateway')) // $isDuplicate = $this->duplicate_transaction($user_id, $sub_id, $amount, $currency, $timestamp, $response['id'], $response['status'], $note); // else // $isDuplicate = $this->_check_duplicate_transaction($user_id, $sub_id, $amount, $currency, $timestamp, $response['id'], $response['status'], $note); // if(!$isDuplicate) { // Update to work with latest 3.5.x Membership version // and keep backward compatibility with older versions as well if (!class_exists('Membership_Gateway')) { $this->record_transaction($user_id, $sub_id, $amount, $currency, $timestamp, $response['id'], $response['status'], $note); } else { $this->_record_transaction($user_id, $sub_id, $amount, $currency, $timestamp, $response['id'], $response['status'], $note); } do_action('membership_payment_processed', $user_id, $sub_id, $amount, $currency, $response['id']); // create_subscription $member = new M_Membership($user_id); if ($member) { $member->create_subscription($sub_id, $this->gateway); } do_action('membership_payment_subscr_signup', $user_id, $sub_id); // } break; case 'invalid': // payment has been deemed invalid. bad transaction! $note = 'This payment has been marked as invalid. Do not process membership! BitPay Invoice ID: ' . $response['id']; $amount = $response['price']; $currency = $response['currency']; list($timestamp, $user_id, $sub_id, $key) = explode(':', $response['posData']); // Update to work with latest 3.5.x Membership version // and keep backward compatibility with older versions as well if (!class_exists('Membership_Gateway')) { $this->record_transaction($user_id, $sub_id, $amount, $currency, $timestamp, $response['id'], $response['status'], $note); } else { $this->_record_transaction($user_id, $sub_id, $amount, $currency, $timestamp, $response['id'], $response['status'], $note); } $member = new M_Membership($user_id); if ($member) { $member->expire_subscription($sub_id); $member->deactivate(); } do_action('membership_payment_denied', $user_id, $sub_id, $amount, $currency, $response['id']); break; // Since we want instant membership activation, the paid status is combined with the confirmed // and completed statuses above. In the future if you want to change that, remove the paid: switch // above and uncomment this code: /*case 'paid': // payment has been made but confirmation pending $pending_str = 'BitPay payment received. Awaiting confirmation. BitPay Invoice ID: ' . $response['id']; $reason = 'paid'; $note = $pending_str; $amount = $response['price']; $currency = $response['currency']; $timestamp = $response['currentTime']; // Update to work with latest 3.5.x Membership version // and keep backward compatibility with older versions as well if (!class_exists('Membership_Gateway')) $this->record_transaction($user_id, $sub_id, $amount, $currency, $timestamp, $response['id'], $response['status'], $note); else $this->_record_transaction($user_id, $sub_id, $amount, $currency, $timestamp, $response['id'], $response['status'], $note); do_action('membership_payment_pending', $user_id, $sub_id, $amount, $currency, $response['id']); break; */ // Since we want instant membership activation, the paid status is combined with the confirmed // and completed statuses above. In the future if you want to change that, remove the paid: switch // above and uncomment this code: /*case 'paid': // payment has been made but confirmation pending $pending_str = 'BitPay payment received. Awaiting confirmation. BitPay Invoice ID: ' . $response['id']; $reason = 'paid'; $note = $pending_str; $amount = $response['price']; $currency = $response['currency']; $timestamp = $response['currentTime']; // Update to work with latest 3.5.x Membership version // and keep backward compatibility with older versions as well if (!class_exists('Membership_Gateway')) $this->record_transaction($user_id, $sub_id, $amount, $currency, $timestamp, $response['id'], $response['status'], $note); else $this->_record_transaction($user_id, $sub_id, $amount, $currency, $timestamp, $response['id'], $response['status'], $note); do_action('membership_payment_pending', $user_id, $sub_id, $amount, $currency, $response['id']); break; */ default: // case: various error cases break; } } else { // Did not find expected POST variables. Possible access attempt from a non BitPay site. header('Status: 404 Not Found'); echo 'Error: Missing POST variables. Identification is not possible.'; exit; } }