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 3.9 3.9-beta 3.9.1 3.9.2 3.9.3 4.0 4.0.1 4.0.2 4.0.3 4.1 4.1-beta 4.1.1 4.1.2 4.2 4.2-beta 4.2.1 4.2.2 4.3 4.3.1 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6 4.6.1 4.7 4.8 4.8.1 4.9 4.9.1 4.9.2 5.0 5.0.1
contact-form-7 / modules / stripe / api.php
contact-form-7 / modules / stripe Last commit date
api.php 3 years ago index.asset.php 3 years ago index.js 4 years ago service.php 3 years ago stripe.php 3 years ago style.css 4 years ago
api.php
155 lines
1 <?php
2
3 /**
4 * Class for the Stripe API.
5 *
6 * @link https://stripe.com/docs/api
7 */
8 class WPCF7_Stripe_API {
9
10 const api_version = '2022-08-01';
11 const partner_id = 'pp_partner_HHbvqLh1AaO7Am';
12 const app_name = 'WordPress Contact Form 7';
13 const app_url = 'https://contactform7.com/stripe-integration/';
14
15 private $secret;
16
17
18 /**
19 * Constructor.
20 *
21 * @param string $secret Secret key.
22 */
23 public function __construct( $secret ) {
24 $this->secret = $secret;
25 }
26
27
28 /**
29 * Sends a debug information for a remote request to the PHP error log.
30 *
31 * @param string $url URL to retrieve.
32 * @param array $request Request arguments.
33 * @param array|WP_Error $response The response or WP_Error on failure.
34 */
35 private function log( $url, $request, $response ) {
36 wpcf7_log_remote_request( $url, $request, $response );
37 }
38
39
40 /**
41 * Returns default set of HTTP request headers used for Stripe API.
42 *
43 * @link https://stripe.com/docs/building-plugins#setappinfo
44 *
45 * @return array An associative array of headers.
46 */
47 private function default_headers() {
48 $app_info = array(
49 'name' => self::app_name,
50 'partner_id' => self::partner_id,
51 'url' => self::app_url,
52 'version' => WPCF7_VERSION,
53 );
54
55 $ua = array(
56 'lang' => 'php',
57 'lang_version' => PHP_VERSION,
58 'application' => $app_info,
59 );
60
61 $headers = array(
62 'Authorization' => sprintf( 'Bearer %s', $this->secret ),
63 'Stripe-Version' => self::api_version,
64 'X-Stripe-Client-User-Agent' => json_encode( $ua ),
65 'User-Agent' => sprintf(
66 '%1$s/%2$s (%3$s)',
67 self::app_name,
68 WPCF7_VERSION,
69 self::app_url
70 ),
71 );
72
73 return $headers;
74 }
75
76
77 /**
78 * Creates a Payment Intent.
79 *
80 * @link https://stripe.com/docs/api/payment_intents/create
81 *
82 * @param string|array $args Optional. Arguments to control behavior.
83 * @return array|bool An associative array if 200 OK, false otherwise.
84 */
85 public function create_payment_intent( $args = '' ) {
86 $args = wp_parse_args( $args, array(
87 'amount' => 0,
88 'currency' => '',
89 'receipt_email' => '',
90 ) );
91
92 if ( ! is_email( $args['receipt_email'] ) ) {
93 unset( $args['receipt_email'] );
94 }
95
96 $endpoint = 'https://api.stripe.com/v1/payment_intents';
97
98 $request = array(
99 'headers' => $this->default_headers(),
100 'body' => $args,
101 );
102
103 $response = wp_remote_post( sanitize_url( $endpoint ), $request );
104
105 if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
106 if ( WP_DEBUG ) {
107 $this->log( $endpoint, $request, $response );
108 }
109
110 return false;
111 }
112
113 $response_body = wp_remote_retrieve_body( $response );
114 $response_body = json_decode( $response_body, true );
115
116 return $response_body;
117 }
118
119
120 /**
121 * Retrieve a Payment Intent.
122 *
123 * @link https://stripe.com/docs/api/payment_intents/retrieve
124 *
125 * @param string $id Payment Intent identifier.
126 * @return array|bool An associative array if 200 OK, false otherwise.
127 */
128 public function retrieve_payment_intent( $id ) {
129 $endpoint = sprintf(
130 'https://api.stripe.com/v1/payment_intents/%s',
131 urlencode( $id )
132 );
133
134 $request = array(
135 'headers' => $this->default_headers(),
136 );
137
138 $response = wp_remote_get( sanitize_url( $endpoint ), $request );
139
140 if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
141 if ( WP_DEBUG ) {
142 $this->log( $endpoint, $request, $response );
143 }
144
145 return false;
146 }
147
148 $response_body = wp_remote_retrieve_body( $response );
149 $response_body = json_decode( $response_body, true );
150
151 return $response_body;
152 }
153
154 }
155