| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class stripe payment |
| 4 |
* |
| 5 |
* @package Timetics |
| 6 |
*/ |
| 7 |
namespace Timetics\Core\Integrations\Stripe; |
| 8 |
|
| 9 |
/** |
| 10 |
* Class StripePayment |
| 11 |
*/ |
| 12 |
class StripePayment { |
| 13 |
/** |
| 14 |
* Store stripe paymentintent api url |
| 15 |
* |
| 16 |
* @var string |
| 17 |
*/ |
| 18 |
private $payment_intent_url = 'https://api.stripe.com/v1/payment_intents'; |
| 19 |
|
| 20 |
/** |
| 21 |
* Create stripe paymentintent |
| 22 |
* |
| 23 |
* @param array $args Stripe payment details |
| 24 |
* |
| 25 |
* @return array |
| 26 |
*/ |
| 27 |
public function create_payment( $args = [] ) { |
| 28 |
$defaults = [ |
| 29 |
'amount' => '', |
| 30 |
'currency' => '', |
| 31 |
]; |
| 32 |
|
| 33 |
$args = wp_parse_args( $args, $defaults ); |
| 34 |
|
| 35 |
$url = $this->payment_intent_url; |
| 36 |
$secret = timetics_get_option( 'stripe_secret_key' ); |
| 37 |
$args = build_query( $args ) . '&automatic_payment_methods[enabled]=true'; |
| 38 |
$params = [ |
| 39 |
'headers' => [ |
| 40 |
'Authorization' => 'Bearer ' . $secret, |
| 41 |
'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8', |
| 42 |
], |
| 43 |
'body' => $args, |
| 44 |
]; |
| 45 |
|
| 46 |
$response = wp_remote_post( $url, $params ); |
| 47 |
|
| 48 |
if ( ! is_wp_error( $response ) ) { |
| 49 |
return json_decode( wp_remote_retrieve_body( $response ), true ); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Added temporary for leagacy sass. It will remove in future. |
| 54 |
*/ |
| 55 |
do_action( 'timetics/integrations/stripe/create_payment', $response ); |
| 56 |
|
| 57 |
return $response; |
| 58 |
} |
| 59 |
} |
| 60 |
|