Ejemplo n.º 1
0
function CreateBitPayInvoice($loginState)
{
    $paid = GetIsPaid($loginState);
    if (!$paid['accept']) {
        DebugMessage("User " . $loginState['id'] . " attempted to create BitPay invoice when we would not accept payments.");
        return [];
    }
    $priceAmount = preg_match('/\\d+\\.\\d+/', SUBSCRIPTION_PAID_PRICE, $res) ? $res[0] : false;
    $priceCurrency = preg_match('/\\b[A-Z]{3}\\b/', SUBSCRIPTION_PAID_PRICE, $res) ? $res[0] : false;
    if (!$priceAmount || !$priceCurrency) {
        DebugMessage("Could not find price ({$priceAmount}) or currency ({$priceCurrency}) from " . SUBSCRIPTION_PAID_PRICE . " when creating BitPay invoice.");
        return [];
    }
    $LANG = GetLang($loginState['locale']);
    $toPost = ['price' => $priceAmount, 'currency' => $priceCurrency, 'posData' => $paid['accept']['custom'], 'fullNotifications' => true, 'notificationURL' => SUBSCRIPTION_BITPAY_IPN_URL, 'notificationEmail' => SUBSCRIPTION_ERRORS_EMAIL_ADDRESS, 'redirectURL' => 'https://' . strtolower($_SERVER["HTTP_HOST"]) . '/#subscription', 'itemDesc' => $LANG['paidSubscription'] . ' - ' . round(SUBSCRIPTION_PAID_ADDS_SECONDS / 86400) . ' ' . $LANG['timeDays']];
    $headers = ['Content-Type: application/json; charset=utf-8', 'Authorization: Basic ' . base64_encode(SUBSCRIPTION_BITPAY_KEY . ':')];
    $jsonString = \Newsstand\HTTP::Post(SUBSCRIPTION_BITPAY_INVOICE_URL, json_encode($toPost), $headers);
    if (!$jsonString) {
        DebugMessage("No response from BitPay having sent:\n" . json_encode($toPost) . "\n" . print_r($headers, true));
        return [];
    }
    $json = json_decode($jsonString, true);
    if (json_last_error() != JSON_ERROR_NONE) {
        DebugMessage("Invalid response from BitPay:\n{$jsonString}\nHaving sent:\n" . json_encode($toPost) . "\n" . print_r($headers, true));
        return [];
    }
    if (!UpdateBitPayTransaction($json, true)) {
        return [];
    }
    return ['url' => $json['url']];
}
Ejemplo n.º 2
0
<?php

// symlinked in / for IPN
require_once __DIR__ . '/../incl/incl.php';
require_once __DIR__ . '/../incl/subscription.incl.php';
$rawPost = file_get_contents('php://input');
if (!UpdateBitPayTransaction($rawPost)) {
    header($_SERVER["SERVER_PROTOCOL"] . ' 500 Internal Server Error');
}