0
X
Add Snippet To Project
New Project
Add To Existing Project
<?php
(function($) {
// Process Paddle payment
function wpturbo_process_paddle_payment() {
// Paddle로 전송할 결제 데이터
var payment_data = {
product_id: 'PRODUCT_ID', // Replace with the product ID from Paddle
email: 'user@example.com' // Replace with the user's email address
};
// Initialize Paddle.js with your vendor ID
Paddle.Setup({
vendor: YOUR_VENDOR_ID // Replace with your Paddle vendor ID
});
// Create a new Checkout instance
var checkout = new Paddle.Checkout({
override: true,
product: payment_data.product_id,
email: payment_data.email,
successCallback: function(data) {
// Payment success callback
console.log('Payment successful:', data);
// Perform additional actions after successful payment
},
closeCallback: function() {
// Payment close callback
console.log('Payment closed');
// Perform additional actions if payment is closed
}
});
// Open the Paddle checkout
checkout.open();
}
$(document).ready(function() {
// Paddle payment handler
$('.purchase-button').click(function() {
wpturbo_process_paddle_payment();
});
// Webhook handler for payment verification
$(document).on('wp_ajax_wpturbo_paddle_payment_verification', function() {
// Get the payment data from the webhook request
$payment_data = $_POST;
// Verify the payment using Paddle API
$verification_url = 'https://vendors.paddle.com/api/2.0/subscription/users';
$auth_token = 'YOUR_PADDLE_AUTH_TOKEN'; // Replace with your Paddle auth token
// Set up the request arguments
$args = array(
'body' => array(
'subscription_id' => $payment_data['subscription_id'],
'email' => $payment_data['email'],
),
'headers' => array(
'Authorization' => 'Basic ' . base64_encode( $auth_token . ':' ),
),
);
// Send the request to Paddle for verification
$response = wp_remote_post( $verification_url, $args );
// Check if the verification was successful
if ( ! is_wp_error( $response ) && wp_remote_retrieve_response_code( $response ) === 200 ) {
// Verification successful, perform actions for verified payment
// ...
} else {
// Verification failed, perform actions for failed verification
// ...
}
});
});
})(jQuery);