Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The requested resource does not support http method 'GET'. #28

Open
akiilles05 opened this issue May 28, 2023 · 0 comments
Open

The requested resource does not support http method 'GET'. #28

akiilles05 opened this issue May 28, 2023 · 0 comments

Comments

@akiilles05
Copy link

Hi!

I would like to ask how to fix the error?

<?php
// Barion fizetési visszatérő oldal (barion-payment.php)

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (isset($_POST['PaymentId']) && isset($_POST['POSId'])) {
        // Ellenőrizd, hogy a POST adatok érkeztek-e a fizetési tranzakcióval kapcsolatban
        $paymentId = $_POST['PaymentId'];
        $posId = $_POST['POSId'];

        // Barion API hívás a fizetés véglegesítéséhez és ellenőrzéséhez
        $barionAPIURL = "https://api.test.barion.com/payment/getstatus";
        $barionAPIPOSKey = "";

        $requestData = array(
            "POSKey" => $barionAPIPOSKey,
            "PaymentId" => $paymentId
        );

        $requestDataJSON = json_encode($requestData);

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $barionAPIURL);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            "Content-Type: application/json"
        ));
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $requestDataJSON);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec($ch);
        curl_close($ch);

        $paymentStatus = json_decode($response, true);

        // Ellenőrizd a fizetési tranzakció státuszát
        if ($paymentStatus['Status'] == "Succeeded") {
            // A fizetés sikeres volt, frissítsd az adatbázist a vásárolt PP pontokkal
            $ppPontok = $paymentStatus['Transactions'][0]['Total'];

            // Adatbázis frissítése
            // ...

            echo 'Sikeres fizetés!';
        } else {
            // A fizetés sikertelen volt
            echo 'Sikertelen fizetés!';
        }
    } else {
        // Hiányzó POST adatok esetén
        echo 'Sikertelen fizetés!';
    }
}
?>
<?php
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        $barionPOSKey = "";
        $barionRedirectURL = "https://neonnights.illesinnovate.hu/pp/barion-payment.php";
        
        // Barion fizetési létrehozása
        $barionPaymentURL = "https://api.test.barion.com/v2/Payment/Start";
        
        // Adatok a fizetéshez
        $itemName = $_POST["name_item"];
        $itemDescription = $_POST["name_description"];
        $itemPrice = $_POST["name_price"];
        
        // Fizetési adatok előkészítése
        $paymentData = array(
            "POSKey" => $barionPOSKey,
            "PaymentType" => "Immediate",
            "GuestCheckOut" => true,
            "FundingSources" => ["All"],
            "PaymentRequestId" => uniqid("NNRP-"),
            "PayerHint" => "[email protected]",
            "Transactions" => array(
                array(
                    "POSTransactionId" => uniqid("TRANS-"),
                    "Payee" => "[email protected]",
                    "Total" => 10, // Összeg PP pontok vásárlásához
                    "Items" => array(
                        array(
                            "Name" => $itemName,
                            "Description" => $itemDescription,
                            "Quantity" => 1,
                            "Unit" => "db",
                            "UnitPrice" => $itemPrice, // Ár PP pontonként
                        )
                    )
                )
            ),
            "RedirectUrl" => $barionRedirectURL
        );
        
        $paymentDataJSON = json_encode($paymentData);
        
        // API hívás és válaszfeldolgozás
        
        // Barion fizetési átirányítás helyett API hívás
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $barionPaymentURL);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            "Content-Type: application/json"
        ));
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $paymentDataJSON);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec($ch);
        curl_close($ch);
        
        // Válaszfeldolgozás
        $paymentResponse = json_decode($response, true);   

        if ($paymentResponse['Status'] === 'Succeeded') {
            // A fizetés sikeres volt, folytasd a szükséges tevékenységekkel
            $paymentId = $paymentResponse['PaymentId'];
            $transactionId = $paymentResponse['Transactions'][0]['POSTransactionId'];
            $totalAmount = $paymentResponse['Transactions'][0]['Total'];
        
            // Adatok további feldolgozása vagy adatbázis frissítése
            // ...
        
            echo 'Sikeres fizetés!';
        } else {
            // A fizetés sikertelen volt, kezeld a hibát vagy jelentsd az ügyfeleknek
            $errorMessage = $paymentResponse['Errors'][0]['Description'];
            echo 'Sikertelen fizetés! Hiba: ' . $errorMessage;
        }

        // Barion fizetési átirányítás
        header("Location: $barionPaymentURL");
        exit;
    }
?>

Waiting for your reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant