Hitpay-Zahlungsintegration kann nicht in PHP implementiert werdenPhp

PHP-Programmierer chatten hier
Guest
 Hitpay-Zahlungsintegration kann nicht in PHP implementiert werden

Post by Guest »

Code: Select all

    



HitPay Checkout Drop-in Test Page





// Callback for successful payment
function onSuccess(data) {
console.log('onSuccess called:', data);

// Verify if valid data is received
if (!data) {
console.error('No data received in onSuccess');
const el = document.createElement('p');
el.innerHTML = 'Payment Success, but no data received.';
document.body.appendChild(el);
return;
}

// Display a success message
const el = document.createElement('p');
el.innerHTML = 'Payment Success';
document.body.appendChild(el);

// Send payment details to backend for storage
fetch('store_payment_details.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data), // Sending received data
})
.then((response) => response.json())
.then((response) => {
console.log('Payment details stored successfully:', response);
})
.catch((error) => {
console.error('Error storing payment details:', error);
});
}

// Callback when payment is closed
function onClose(data) {
console.log('onClose called:', data);
const el = document.createElement('p');
el.innerHTML = 'Payment Closed';
document.body.appendChild(el);
}

// Callback for errors
function onError(error) {
console.error('onError called:', error);
const el = document.createElement('p');
el.innerHTML = 'Error: ' + (error.message || error);
document.body.appendChild(el);
}

// Function to initiate payment
function onClick() {
const carttotalValue = 1; // Dynamic total value (e.g., 100 for testing)
const paymentData = {
amount: carttotalValue, // Ensure amount matches cart total
currency: 'SGD',
email: '[email protected]',
phone: '1111',
order_id: '123',
};

// Make AJAX request to backend to create the payment request
fetch('hitpay_payment_request.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(paymentData), // Send dynamic data
})
.then((response) => response.json())
.then((response) => {
const data = response.data;
console.log("data=",data);
if (data && data.id) {
// Initialize HitPay only once
if (!window.HitPay.inited) {
window.HitPay.init(
'https://securecheckout.hit-pay.com/payment-request/@curvv-tech-private-limited',
{
domain: 'hit-pay.com',
apiDomain: 'hit-pay.com',
},
{
onClose: onClose,
onSuccess: onSuccess,
onError: onError,
}
);
}

// Trigger the payment gateway toggle with the provided payment_url
window.HitPay.toggle({
paymentRequest: data.id, // Dynamic payment ID
amount: carttotalValue,
name: 'Anbu',
phone: '93500239',
});
} else {
// Handle error if no payment URL is received
console.error('Error: Payment URL not received');
}
})
.catch((error) =>  {
console.error('AJAX Error:', error);
});
}


Pay




> response getting

{
"data": {
"id": "9de0c639-c986-4743-a1ae-70b998068536",
"name": null,
"email": "[email protected]",
"phone": "1111",
"amount": "1.00",
"currency": "SGD",
"is_currency_editable": false,
"status": "pending",
"purpose": null,
"reference_number": "123",
"payment_methods": [
"card",
"paynow_online"
],
"url": "https:\/\/securecheckout.hit-pay.com\/payment-request\/@curvv-tech-private-limited\/9de0c639-c986-4743-a1ae-70b998068536\/checkout",
"redirect_url": "https:\/\/domain.sg\/hit-pay\/hitpay_payment_success.php",
"webhook": "https:\/\/domain.sg\/hit-pay\/hitpay_payment_details.php",
"send_sms": false,
"send_email": false,
"sms_status": "pending",
"email_status": "pending",
"allow_repeated_payments": false,
"expiry_date": null,
"address": null,
"line_items": null,
"executor_id": null,
"created_at": "2025-01-03T14:53:59",
"updated_at": "2025-01-03T14:53:59",
"staff_id": null,
"business_location_id": null
}
}

> hitpay_payment_deatils.php


>hitpay_payment_success.php


Ich versuche, das HitPay-Zahlungsgateway zu implementieren.
Ich kann die Antwort auf die Zahlungsanforderung erfolgreich erhalten.
Das tue ich auch Ich kann die Zahlung abschließen.
Nach der Zahlung muss ich jedoch die Transaktionsdetails speichern, wie zum Beispiel:
Transaktions-ID
Transaktionsstatus und andere Relevante Details.
Aus irgendeinem Grund funktioniert dieser Teil nicht erwartet.
Ich habe viele Ansätze ausprobiert, aber ich kann das Problem nicht identifizieren.
Kann mir jemand dabei helfen? Ich brauche eine ausführliche Erklärung.

Code: Select all

[Reference link here][1]

[1]: https://docs.hitpayapp.com/apis/guide/online-payments

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post