| Server IP : 151.101.66.159 / Your IP : 216.73.216.66 Web Server : Flywheel/5.1.0 System : Linux wordpress 6.12.113+ #1 SMP Thu Oct 22 02:38:20 UTC 2026 x86_64 User : root ( ) PHP Version : 7.4.33.18 Disable Function : disk_free_space,diskfreespace,dl,exec,fpassthru,getmypid,getmyuid,highlight_file,link,opcache_compile_file,opcache_get_configuration,opcache_is_script_cached,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifcontinued,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,phpinfo,popen,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,show_source,socket_listen,source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wp-content/plugins/contact-form-7/modules/stripe/ |
Upload File : |
<?php
/**
* Class for the Stripe API.
*
* @link https://docs.stripe.com/api
*/
class WPCF7_Stripe_API {
const api_version = '2022-11-15';
const partner_id = 'pp_partner_HHbvqLh1AaO7Am';
const app_name = 'WordPress Contact Form 7';
const app_url = 'https://contactform7.com/stripe-integration/';
private $secret;
/**
* Constructor.
*
* @param string $secret Secret key.
*/
public function __construct( $secret ) {
$this->secret = $secret;
}
/**
* Sends a debug information for a remote request to the PHP error log.
*
* @param string $url URL to retrieve.
* @param array $request Request arguments.
* @param array|WP_Error $response The response or WP_Error on failure.
*/
private function log( $url, $request, $response ) {
wpcf7_log_remote_request( $url, $request, $response );
}
/**
* Returns default set of HTTP request headers used for Stripe API.
*
* @link https://docs.stripe.com/building-plugins#setappinfo
*
* @return array An associative array of headers.
*/
private function default_headers() {
$app_info = array(
'name' => self::app_name,
'partner_id' => self::partner_id,
'url' => self::app_url,
'version' => WPCF7_VERSION,
);
$ua = array(
'lang' => 'php',
'lang_version' => PHP_VERSION,
'application' => $app_info,
);
$headers = array(
'Authorization' => sprintf( 'Bearer %s', $this->secret ),
'Stripe-Version' => self::api_version,
'X-Stripe-Client-User-Agent' => wp_json_encode( $ua ),
'User-Agent' => sprintf(
'%1$s/%2$s (%3$s)',
self::app_name,
WPCF7_VERSION,
self::app_url
),
);
return $headers;
}
/**
* Creates a Payment Intent.
*
* @link https://docs.stripe.com/api/payment_intents/create
*
* @param string|array $args Optional. Arguments to control behavior.
* @return array|bool An associative array if 200 OK, false otherwise.
*/
public function create_payment_intent( $args = '' ) {
$args = wp_parse_args( $args, array(
'amount' => 0,
'currency' => '',
'receipt_email' => '',
) );
if ( ! is_email( $args['receipt_email'] ) ) {
unset( $args['receipt_email'] );
}
$endpoint = 'https://api.stripe.com/v1/payment_intents';
$request = array(
'headers' => $this->default_headers(),
'body' => $args,
);
$response = wp_remote_post( sanitize_url( $endpoint ), $request );
if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
if ( WP_DEBUG ) {
$this->log( $endpoint, $request, $response );
}
return false;
}
$response_body = wp_remote_retrieve_body( $response );
$response_body = json_decode( $response_body, true );
return $response_body;
}
/**
* Retrieves a Payment Intent.
*
* @link https://docs.stripe.com/api/payment_intents/retrieve
*
* @param string $id Payment Intent identifier.
* @return array|bool An associative array if 200 OK, false otherwise.
*/
public function retrieve_payment_intent( $id ) {
$endpoint = sprintf(
'https://api.stripe.com/v1/payment_intents/%s',
urlencode( $id )
);
$request = array(
'headers' => $this->default_headers(),
);
$response = wp_remote_get( sanitize_url( $endpoint ), $request );
if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
if ( WP_DEBUG ) {
$this->log( $endpoint, $request, $response );
}
return false;
}
$response_body = wp_remote_retrieve_body( $response );
$response_body = json_decode( $response_body, true );
return $response_body;
}
/**
* Updates a Payment Intent.
*
* @link https://docs.stripe.com/api/payment_intents/update
*
* @param string $id Payment Intent identifier.
* @param array $parameters Parameters.
* @return array|bool An associative array if 200 OK, false otherwise.
*/
public function update_payment_intent( $id, $parameters ) {
$endpoint = sprintf(
'https://api.stripe.com/v1/payment_intents/%s',
urlencode( $id )
);
$request = array(
'headers' => $this->default_headers(),
'body' => wp_parse_args( $parameters, array() ),
);
$response = wp_remote_post( sanitize_url( $endpoint ), $request );
if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
if ( WP_DEBUG ) {
$this->log( $endpoint, $request, $response );
}
return false;
}
$response_body = wp_remote_retrieve_body( $response );
$response_body = json_decode( $response_body, true );
return $response_body;
}
}