init
This commit is contained in:
+2885
File diff suppressed because it is too large
Load Diff
+97
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* WC_Payments_Http_Interface class.
|
||||
*
|
||||
* @package WooCommerce\Payments
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use WCPay\Exceptions\API_Exception;
|
||||
|
||||
/**
|
||||
* A wrapper around Jetpack HTTP request library. Necessary to increase
|
||||
* the testability of WC_Payments_API_Client, and allow dependency
|
||||
* injection.
|
||||
*/
|
||||
interface WC_Payments_Http_Interface {
|
||||
|
||||
/**
|
||||
* Sends a remote request through Jetpack.
|
||||
*
|
||||
* @param array $args - The arguments to passed to Jetpack.
|
||||
* @param string $body - The body passed on to the HTTP request.
|
||||
* @param bool $is_site_specific - If true, the site ID will be included in the request url. Defaults to true.
|
||||
* @param bool $use_user_token - If true, the request will be signed with the user token rather than blog token. Defaults to false.
|
||||
*
|
||||
* @return array HTTP response on success.
|
||||
* @throws API_Exception - If not connected or request failed.
|
||||
*/
|
||||
public function remote_request( $args, $body = null, $is_site_specific = true, $use_user_token = false );
|
||||
|
||||
/**
|
||||
* Checks if Jetpack is connected.
|
||||
*
|
||||
* Checks if connection is authenticated in the same way as Jetpack_Client or Jetpack Connection Client does.
|
||||
*
|
||||
* @return bool true if Jetpack connection has access token.
|
||||
*/
|
||||
public function is_connected();
|
||||
|
||||
/**
|
||||
* Checks if the site has an admin who is also a connection owner.
|
||||
*
|
||||
* @return bool True if Jetpack connection has an owner.
|
||||
*/
|
||||
public function has_connection_owner();
|
||||
|
||||
/**
|
||||
* Checks if the current user is connected to WordPress.com.
|
||||
*
|
||||
* @return bool true if the current user is connected.
|
||||
*/
|
||||
public function is_user_connected();
|
||||
|
||||
/**
|
||||
* Get the wpcom user data of the current connected user.
|
||||
*
|
||||
* @return bool|array An array with the WPCOM user data on success, false otherwise.
|
||||
*/
|
||||
public function get_connected_user_data();
|
||||
|
||||
/**
|
||||
* Gets the current WP.com blog ID.
|
||||
*
|
||||
* @return integer Current WPCOM blog ID.
|
||||
*/
|
||||
public function get_blog_id();
|
||||
|
||||
/**
|
||||
* Starts the Jetpack connection process. Note that running this function will immediately redirect
|
||||
* to the Jetpack flow, so any PHP code after it will never be executed.
|
||||
*
|
||||
* @param string $redirect - URL to redirect to after the connection process is over.
|
||||
*
|
||||
* @throws API_Exception - Exception thrown on failure.
|
||||
*/
|
||||
public function start_connection( $redirect );
|
||||
|
||||
/**
|
||||
* Queries the WordPress.com REST API with a user token.
|
||||
*
|
||||
* @param string $path REST API path.
|
||||
* @param string $version REST API version. Default is `2`.
|
||||
* @param array $args Arguments to {@see WP_Http}. Default is `array()`.
|
||||
* @param string|array $body Body passed to {@see WP_Http}. Default is `null`.
|
||||
* @param string $base_api_path REST API root. Default is `wpcom`.
|
||||
*
|
||||
* @return array|WP_Error $response Response data, else {@see WP_Error} on failure.
|
||||
*/
|
||||
public function wpcom_json_api_request_as_user(
|
||||
$path,
|
||||
$version = '2',
|
||||
$args = [],
|
||||
$body = null,
|
||||
$base_api_path = 'wpcom'
|
||||
);
|
||||
}
|
||||
+223
@@ -0,0 +1,223 @@
|
||||
<?php
|
||||
/**
|
||||
* WC_Payments_Http class.
|
||||
*
|
||||
* @package WooCommerce\Payments
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use WCPay\Exceptions\API_Exception;
|
||||
use WCPay\Exceptions\Connection_Exception;
|
||||
use WCPay\Logger;
|
||||
|
||||
/**
|
||||
* A wrapper around Jetpack HTTP request library. Necessary to increase
|
||||
* the testability of WC_Payments_API_Client, and allow dependency
|
||||
* injection.
|
||||
*/
|
||||
class WC_Payments_Http implements WC_Payments_Http_Interface {
|
||||
|
||||
/**
|
||||
* Jetpack connection handler.
|
||||
*
|
||||
* @var Automattic\Jetpack\Connection\Manager
|
||||
*/
|
||||
private $connection_manager;
|
||||
|
||||
/**
|
||||
* WC_Payments_Http constructor.
|
||||
*
|
||||
* @param Automattic\Jetpack\Connection\Manager $connection_manager - Jetpack connection handler.
|
||||
*/
|
||||
public function __construct( $connection_manager ) {
|
||||
$this->connection_manager = $connection_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes this class's WP hooks.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init_hooks() {
|
||||
add_filter( 'allowed_redirect_hosts', [ $this, 'allowed_redirect_hosts' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a remote request through Jetpack.
|
||||
*
|
||||
* @param array $args - The arguments to passed to Jetpack.
|
||||
* @param string $body - The body passed on to the HTTP request.
|
||||
* @param bool $is_site_specific - If true, the site ID will be included in the request url. Defaults to true.
|
||||
* @param bool $use_user_token - If true, the request will be signed with the Jetpack connection owner user token rather than blog token. Defaults to false.
|
||||
*
|
||||
* @return array HTTP response on success.
|
||||
* @throws API_Exception - If not connected or request failed.
|
||||
*/
|
||||
public function remote_request( $args, $body = null, $is_site_specific = true, $use_user_token = false ) {
|
||||
// Make sure we're not sending requests if Jetpack is not connected.
|
||||
if ( ! $this->is_connected() ) {
|
||||
Logger::error( 'HTTP_REQUEST_ERROR Site is not connected to WordPress.com' );
|
||||
throw new API_Exception(
|
||||
__( 'Site is not connected to WordPress.com', 'woocommerce-payments' ),
|
||||
'wcpay_wpcom_not_connected',
|
||||
409 // HTTP Conflict status code.
|
||||
);
|
||||
}
|
||||
|
||||
$args['blog_id'] = $this->get_blog_id();
|
||||
|
||||
if ( $use_user_token ) {
|
||||
$args['user_id'] = $this->connection_manager->get_connection_owner_id();
|
||||
}
|
||||
|
||||
if ( $is_site_specific ) {
|
||||
// We expect `url` to include a `%s` placeholder which will allow us inject the blog id.
|
||||
$url = explode( '?', $args['url'], 2 );
|
||||
$url[0] = sprintf( $url[0], $args['blog_id'] );
|
||||
$args['url'] = implode( '?', $url );
|
||||
}
|
||||
|
||||
return self::make_request( $args, $body );
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries the WordPress.com REST API with a user token.
|
||||
*
|
||||
* @param string $path REST API path.
|
||||
* @param string $version REST API version. Default is `2`.
|
||||
* @param array $args Arguments to {@see WP_Http}. Default is `array()`.
|
||||
* @param string|array $body Body passed to {@see WP_Http}. Default is `null`.
|
||||
* @param string $base_api_path REST API root. Default is `wpcom`.
|
||||
*
|
||||
* @return array|\WP_Error $response Response data, else WP_Error on failure.
|
||||
*/
|
||||
public function wpcom_json_api_request_as_user(
|
||||
$path,
|
||||
$version = '2',
|
||||
$args = [],
|
||||
$body = null,
|
||||
$base_api_path = 'wpcom'
|
||||
) {
|
||||
return Automattic\Jetpack\Connection\Client::wpcom_json_api_request_as_user( $path, $version, $args, $body, $base_api_path );
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a request through Jetpack.
|
||||
*
|
||||
* @param array $args - The arguments passed to Jetpack.
|
||||
* @param string $body - The body passed to the HTTP request.
|
||||
*
|
||||
* @return array HTTP response on success.
|
||||
* @throws Connection_Exception - If request returns WP_Error.
|
||||
*/
|
||||
private static function make_request( $args, $body ) {
|
||||
$response = Automattic\Jetpack\Connection\Client::remote_request( $args, $body );
|
||||
|
||||
if ( is_wp_error( $response ) || ! is_array( $response ) ) {
|
||||
Logger::error( 'HTTP_REQUEST_ERROR ' . var_export( $response, true ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
|
||||
$message = sprintf(
|
||||
// translators: %1: original error message.
|
||||
__( 'Http request failed. Reason: %1$s', 'woocommerce-payments' ),
|
||||
$response->get_error_message()
|
||||
);
|
||||
throw new Connection_Exception( $message, 'wcpay_http_request_failed', 500 );
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if Jetpack is connected.
|
||||
*
|
||||
* Checks if connection is authenticated in the same way as Jetpack_Client or Jetpack Connection Client does.
|
||||
*
|
||||
* @return bool true if Jetpack connection has access token.
|
||||
*/
|
||||
public function is_connected() {
|
||||
return $this->connection_manager->is_connected() && $this->connection_manager->has_connected_owner();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the current user is connected to WordPress.com.
|
||||
*
|
||||
* @return bool true if the current user is connected.
|
||||
*/
|
||||
public function is_user_connected() {
|
||||
return $this->connection_manager->is_user_connected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the wpcom user data of the current connected user.
|
||||
*
|
||||
* @return bool|array An array with the WPCOM user data on success, false otherwise.
|
||||
*/
|
||||
public function get_connected_user_data() {
|
||||
return $this->connection_manager->get_connected_user_data();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the site has an admin who is also a connection owner.
|
||||
*
|
||||
* @return bool True if Jetpack connection has an owner.
|
||||
*/
|
||||
public function has_connection_owner() {
|
||||
return ! empty( $this->connection_manager->get_connection_owner_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current WP.com blog ID.
|
||||
*
|
||||
* @return integer Current WPCOM blog ID.
|
||||
*/
|
||||
public function get_blog_id() {
|
||||
return Jetpack_Options::get_option( 'id' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the Jetpack connection process. Note that running this function will immediately redirect
|
||||
* to the Jetpack flow, so any PHP code after it will never be executed.
|
||||
*
|
||||
* @param string $redirect - URL to redirect to after the connection process is over.
|
||||
*
|
||||
* @throws API_Exception - Exception thrown on failure.
|
||||
*/
|
||||
public function start_connection( $redirect ) {
|
||||
// Register the site to wp.com.
|
||||
if ( ! $this->connection_manager->is_connected() ) {
|
||||
$result = $this->connection_manager->try_registration();
|
||||
if ( is_wp_error( $result ) ) {
|
||||
throw new API_Exception( $result->get_error_message(), 'wcpay_jetpack_register_site_failed', 500 );
|
||||
}
|
||||
}
|
||||
|
||||
// Redirect the user to the Jetpack user connection flow.
|
||||
add_filter( 'jetpack_use_iframe_authorization_flow', '__return_false' );
|
||||
// Same logic as in WC-Admin.
|
||||
$calypso_env = defined( 'WOOCOMMERCE_CALYPSO_ENVIRONMENT' ) && in_array( WOOCOMMERCE_CALYPSO_ENVIRONMENT, [ 'development', 'wpcalypso', 'horizon', 'stage' ], true ) ? WOOCOMMERCE_CALYPSO_ENVIRONMENT : 'production';
|
||||
wp_safe_redirect(
|
||||
add_query_arg(
|
||||
[
|
||||
'from' => 'woocommerce-core-profiler',
|
||||
'plugin_name' => 'woocommerce-payments',
|
||||
'calypso_env' => $calypso_env,
|
||||
],
|
||||
$this->connection_manager->get_authorization_url( null, $redirect )
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter function to add WP.com to the list of allowed redirect hosts
|
||||
*
|
||||
* @param array $hosts - array of allowed hosts.
|
||||
*
|
||||
* @return array allowed hosts
|
||||
*/
|
||||
public function allowed_redirect_hosts( $hosts ) {
|
||||
$hosts[] = 'jetpack.wordpress.com';
|
||||
return $hosts;
|
||||
}
|
||||
}
|
||||
+219
@@ -0,0 +1,219 @@
|
||||
<?php
|
||||
/**
|
||||
* WC_Payments_API_Abstract_Intention class
|
||||
*
|
||||
* @package WooCommerce\Payments
|
||||
*/
|
||||
|
||||
use WCPay\Constants\Intent_Status;
|
||||
|
||||
/**
|
||||
* An abstract object representing payment and setup intents used by the WooCommerce Payments API.
|
||||
*
|
||||
* Only add shared getters and properties in this class. Otherwise, add them inherited classes.
|
||||
*/
|
||||
abstract class WC_Payments_API_Abstract_Intention implements \JsonSerializable {
|
||||
/**
|
||||
* Intention ID
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* Time charge created
|
||||
*
|
||||
* Server-side times are presumed to be UTC, (de)serializers should take care to set/respect the timezone on the
|
||||
* DateTime object.
|
||||
*
|
||||
* @var DateTime
|
||||
*/
|
||||
protected $created;
|
||||
|
||||
/**
|
||||
* The status of the intention
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $status;
|
||||
|
||||
/**
|
||||
* The client secret of the intention
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $client_secret;
|
||||
|
||||
/**
|
||||
* ID of the customer making the payment
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $customer_id;
|
||||
|
||||
/**
|
||||
* ID of the payment method used.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $payment_method_id;
|
||||
|
||||
/**
|
||||
* The next action needed of the intention
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $next_action;
|
||||
|
||||
/**
|
||||
* Set of key-value pairs that can be useful for storing
|
||||
* additional information about the object in a structured format.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $metadata;
|
||||
|
||||
/**
|
||||
* The possible payment method types for the payment.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $payment_method_types;
|
||||
|
||||
/**
|
||||
* The order data associated with this intention.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $order;
|
||||
|
||||
/**
|
||||
* The payment method options for the payment.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $payment_method_options;
|
||||
|
||||
/**
|
||||
* Gets charge ID
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_id() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets charge created time
|
||||
*
|
||||
* @return DateTime
|
||||
*/
|
||||
public function get_created() {
|
||||
return $this->created;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets intention status
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_status() {
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the client secret associated with this intention
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_client_secret() {
|
||||
return $this->client_secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the customer ID of this intention
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_customer_id() {
|
||||
return $this->customer_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the payment method ID of this intention
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_payment_method_id() {
|
||||
return $this->payment_method_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next action of this intention
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_next_action() {
|
||||
return $this->next_action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the metadata associated with this intention
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_metadata() {
|
||||
return $this->metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the payment_method_types state of this intention
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_payment_method_types() {
|
||||
return $this->payment_method_types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the order data associated with this intention
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_order() {
|
||||
return $this->order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the payment method options associated with this intention
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_payment_method_options() {
|
||||
return $this->payment_method_options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the payment method type used in the intent that is derived from property `payment_method_options`.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_payment_method_type() {
|
||||
$keys = count( (array) $this->payment_method_options ) > 0 ? array_keys( $this->payment_method_options ) : null;
|
||||
return $keys ? $keys[0] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the intention is in one of the authorized statuses.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_authorized(): bool {
|
||||
return in_array( $this->status, Intent_Status::AUTHORIZED_STATUSES, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines which data will be serialized to JSON
|
||||
*/
|
||||
abstract public function jsonSerialize(): array;
|
||||
}
|
||||
+482
@@ -0,0 +1,482 @@
|
||||
<?php
|
||||
/**
|
||||
* WC_Payments_API_Charge class
|
||||
*
|
||||
* @package WooCommerce\Payments
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* A charge object used by the WooCommerce Payments API.
|
||||
*/
|
||||
class WC_Payments_API_Charge implements \JsonSerializable {
|
||||
/**
|
||||
* Charge ID
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* Charge amount
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $amount;
|
||||
|
||||
/**
|
||||
* Time charge created
|
||||
*
|
||||
* Server-side times are presumed to be UTC, (de)serializers should take care to set/respect the timezone on the
|
||||
* DateTime object.
|
||||
*
|
||||
* @var DateTime
|
||||
*/
|
||||
private $created;
|
||||
|
||||
/**
|
||||
* Flag indicated whether the charge has been captured or not
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $captured;
|
||||
|
||||
/**
|
||||
* Payment method details object
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $payment_method_details;
|
||||
|
||||
/**
|
||||
* Payment method id
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
private $payment_method;
|
||||
|
||||
/**
|
||||
* Amount in cents captured
|
||||
*
|
||||
* @var int|null
|
||||
*/
|
||||
private $amount_captured;
|
||||
|
||||
/**
|
||||
* Amount in cents refunded
|
||||
*
|
||||
* @var int|null
|
||||
*/
|
||||
private $amount_refunded;
|
||||
|
||||
/**
|
||||
* The amount of the application fee requested for the charge
|
||||
*
|
||||
* @var int|null
|
||||
*/
|
||||
private $application_fee_amount;
|
||||
|
||||
/**
|
||||
* Balance transaction that describes the impact of this charge on the account balance
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $balance_transaction;
|
||||
|
||||
/**
|
||||
* Billing information associated with the payment method at the time of the transaction
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $billing_details;
|
||||
|
||||
/**
|
||||
* Charge currency
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
private $currency;
|
||||
|
||||
/**
|
||||
* Charge dispute object
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $dispute;
|
||||
|
||||
/**
|
||||
* Flag indicating whether the charge has been disputed or not
|
||||
*
|
||||
* @var bool|null
|
||||
*/
|
||||
private $disputed;
|
||||
|
||||
/**
|
||||
* Charge order object
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $order;
|
||||
|
||||
/**
|
||||
* Details about whether the payment was accepted, and why
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $outcome;
|
||||
|
||||
/**
|
||||
* Flag indicating whether the charge has been paid or not
|
||||
*
|
||||
* @var bool|null
|
||||
*/
|
||||
private $paid;
|
||||
|
||||
/**
|
||||
* Charge paydown object
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $paydown;
|
||||
|
||||
/**
|
||||
* Charge payment intent id
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
private $payment_intent;
|
||||
|
||||
/**
|
||||
* Flag indicating whether the charge has been refunded or not
|
||||
*
|
||||
* @var bool|null
|
||||
*/
|
||||
private $refunded;
|
||||
|
||||
/**
|
||||
* Charge refunds object
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $refunds;
|
||||
|
||||
/**
|
||||
* Charge status
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
private $status;
|
||||
|
||||
/**
|
||||
* WC_Payments_API_Charge constructor.
|
||||
*
|
||||
* @param string $id - ID of the charge.
|
||||
* @param integer $amount - Amount charged.
|
||||
* @param DateTime $created - Time charge created.
|
||||
* @param array $payment_method_details - Payment method details object.
|
||||
* @param string|null $payment_method - Payment method id.
|
||||
* @param int|null $amount_captured - Amount in cents captured.
|
||||
* @param int|null $amount_refunded - Amount in cents refunded.
|
||||
* @param int|null $application_fee_amount - The amount of the application fee requested for the charge.
|
||||
* @param array $balance_transaction - Balance transaction that describes the impact of this charge on the account balance.
|
||||
* @param array $billing_details - Billing information associated with the payment method at the time of the transaction.
|
||||
* @param string|null $currency - Charge currency.
|
||||
* @param array $dispute - Charge dispute object.
|
||||
* @param bool|null $disputed - Flag indicating whether the charge has been disputed or not.
|
||||
* @param array $order - Charge order object.
|
||||
* @param array $outcome - Details about whether the payment was accepted, and why.
|
||||
* @param bool|null $paid - Flag indicating whether the charge has been paid or not.
|
||||
* @param array $paydown - Charge paydown object.
|
||||
* @param string|null $payment_intent - Charge payment intent id.
|
||||
* @param bool|null $refunded - Flag indicating whether the charge has been refunded or not.
|
||||
* @param array $refunds - Charge refunds object.
|
||||
* @param string|null $status - Charge status.
|
||||
*/
|
||||
public function __construct(
|
||||
$id,
|
||||
$amount,
|
||||
DateTime $created,
|
||||
$payment_method_details = [],
|
||||
$payment_method = null,
|
||||
$amount_captured = null,
|
||||
$amount_refunded = null,
|
||||
$application_fee_amount = null,
|
||||
$balance_transaction = [],
|
||||
$billing_details = [],
|
||||
$currency = null,
|
||||
$dispute = [],
|
||||
$disputed = null,
|
||||
$order = [],
|
||||
$outcome = [],
|
||||
$paid = null,
|
||||
$paydown = [],
|
||||
$payment_intent = null,
|
||||
$refunded = null,
|
||||
$refunds = [],
|
||||
$status = null
|
||||
) {
|
||||
$this->id = $id;
|
||||
$this->amount = $amount;
|
||||
$this->created = $created;
|
||||
$this->payment_method_details = $payment_method_details;
|
||||
$this->payment_method = $payment_method;
|
||||
$this->amount_captured = $amount_captured;
|
||||
$this->amount_refunded = $amount_refunded;
|
||||
$this->application_fee_amount = $application_fee_amount;
|
||||
$this->balance_transaction = $balance_transaction;
|
||||
$this->billing_details = $billing_details;
|
||||
$this->currency = $currency;
|
||||
$this->dispute = $dispute;
|
||||
$this->disputed = $disputed;
|
||||
$this->order = $order;
|
||||
$this->outcome = $outcome;
|
||||
$this->paid = $paid;
|
||||
$this->paydown = $paydown;
|
||||
$this->payment_intent = $payment_intent;
|
||||
$this->refunded = $refunded;
|
||||
$this->refunds = $refunds;
|
||||
$this->status = $status;
|
||||
|
||||
// Set default properties.
|
||||
$this->captured = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets charge ID
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_id() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets charge amount
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_amount() {
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets charge created time
|
||||
*
|
||||
* @return DateTime
|
||||
*/
|
||||
public function get_created() {
|
||||
return $this->created;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the charge captured?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_captured() {
|
||||
return $this->captured;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets charge captured flag
|
||||
*
|
||||
* @param bool $captured - Flag indicating capture status of charge.
|
||||
*/
|
||||
public function set_captured( $captured ) {
|
||||
$this->captured = $captured;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the payment method details associated with this charge
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_payment_method_details() {
|
||||
return $this->payment_method_details;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the payment method id associated with this charge
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_payment_method() {
|
||||
return $this->payment_method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount captured associated with this charge
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function get_amount_captured() {
|
||||
return $this->amount_captured;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount refunded associated with this charge
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function get_amount_refunded() {
|
||||
return $this->amount_refunded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the application fee amount associated with this charge
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function get_application_fee_amount() {
|
||||
return $this->application_fee_amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the balance transaction associated with this charge
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_balance_transaction() {
|
||||
return $this->balance_transaction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the billing details associated with this charge
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_billing_details() {
|
||||
return $this->billing_details;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currency associated with this charge
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_currency() {
|
||||
return $this->currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the dispute object associated with this charge
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_dispute() {
|
||||
return $this->dispute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the disputed flag associated with this charge
|
||||
*
|
||||
* @return bool|null
|
||||
*/
|
||||
public function get_disputed() {
|
||||
return $this->disputed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the order object associated with this charge
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_order() {
|
||||
return $this->order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the outcome object associated with this charge
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_outcome() {
|
||||
return $this->outcome;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the paid flag associated with this charge
|
||||
*
|
||||
* @return bool|null
|
||||
*/
|
||||
public function get_paid() {
|
||||
return $this->paid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the paydown object associated with this charge
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_paydown() {
|
||||
return $this->paydown;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the payment intent id associated with this charge
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_payment_intent() {
|
||||
return $this->payment_intent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the refunded flag associated with this charge
|
||||
*
|
||||
* @return bool|null
|
||||
*/
|
||||
public function get_refunded() {
|
||||
return $this->refunded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the refund object associated with this charge
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_refunds() {
|
||||
return $this->refunds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status associated with this charge
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_status() {
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Defines which data will be serialized to JSON
|
||||
*/
|
||||
public function jsonSerialize(): array {
|
||||
return [
|
||||
'id' => $this->get_id(),
|
||||
'amount' => $this->get_amount(),
|
||||
'created' => $this->get_created()->getTimestamp(),
|
||||
'payment_method_details' => $this->get_payment_method_details(),
|
||||
'payment_method' => $this->get_payment_method(),
|
||||
'amount_captured' => $this->get_amount_captured(),
|
||||
'amount_refunded' => $this->get_amount_refunded(),
|
||||
'application_fee_amount' => $this->get_application_fee_amount(),
|
||||
'balance_transaction' => $this->get_balance_transaction(),
|
||||
'billing_details' => $this->get_billing_details(),
|
||||
'currency' => $this->get_currency(),
|
||||
'dispute' => $this->get_dispute(),
|
||||
'disputed' => $this->get_disputed(),
|
||||
'order' => $this->get_order(),
|
||||
'outcome' => $this->get_outcome(),
|
||||
'paid' => $this->get_paid(),
|
||||
'paydown' => $this->get_paydown(),
|
||||
'payment_intent' => $this->get_payment_intent(),
|
||||
'captured' => $this->is_captured(),
|
||||
'refunded' => $this->get_refunded(),
|
||||
'refunds' => $this->get_refunds(),
|
||||
'status' => $this->get_status(),
|
||||
];
|
||||
}
|
||||
}
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
/**
|
||||
* WC_Payments_API_Intention class
|
||||
*
|
||||
* @package WooCommerce\Payments
|
||||
*/
|
||||
|
||||
/**
|
||||
* Payment Intent object used by the WooCommerce Payments API.
|
||||
*
|
||||
* Only add getters and properties existing in payment intent object https://stripe.com/docs/api/payment_intents/object.
|
||||
* Otherwise, add them in the (abstract) parent class.
|
||||
*/
|
||||
class WC_Payments_API_Payment_Intention extends WC_Payments_API_Abstract_Intention {
|
||||
/**
|
||||
* Charge amount
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $amount;
|
||||
|
||||
/**
|
||||
* The currency of the intention
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $currency;
|
||||
|
||||
/**
|
||||
* The last payment error of the intention
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $last_payment_error;
|
||||
|
||||
/**
|
||||
* The latest charge object
|
||||
*
|
||||
* @var WC_Payments_API_Charge
|
||||
*/
|
||||
private $charge;
|
||||
|
||||
/**
|
||||
* The details on the state of the payment.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $processing;
|
||||
|
||||
/**
|
||||
* WC_Payments_API_Intention constructor.
|
||||
*
|
||||
* @param string $id - ID of the intention.
|
||||
* @param integer $amount - Amount charged.
|
||||
* @param string $currency - The currency of the intention.
|
||||
* @param string|null $customer_id - Stripe ID of the customer.
|
||||
* @param string|null $payment_method_id - Stripe ID of the payment method.
|
||||
* @param DateTime $created - Time charge created.
|
||||
* @param string $status - Intention status.
|
||||
* @param string $client_secret - The client secret of the intention.
|
||||
* @param WC_Payments_API_Charge $charge - An array containing payment method details of associated charge.
|
||||
* @param array $next_action - An array containing information for next action to take.
|
||||
* @param array $last_payment_error - An array containing details of any errors.
|
||||
* @param array $metadata - An array containing additional metadata of associated charge or order.
|
||||
* @param array $processing - An array containing details of the processing state of the payment.
|
||||
* @param array $payment_method_types - An array containing the possible payment methods for the intent.
|
||||
* @param array $payment_method_options - An array containing the payment method options for the intent.
|
||||
* @param array $order - An array containing the order data associated with this intention.
|
||||
*/
|
||||
public function __construct(
|
||||
$id,
|
||||
$amount,
|
||||
string $currency,
|
||||
$customer_id,
|
||||
$payment_method_id,
|
||||
DateTime $created,
|
||||
$status,
|
||||
$client_secret,
|
||||
$charge = null,
|
||||
$next_action = [],
|
||||
$last_payment_error = [],
|
||||
$metadata = [],
|
||||
$processing = [],
|
||||
$payment_method_types = [],
|
||||
$payment_method_options = [],
|
||||
$order = []
|
||||
) {
|
||||
$this->id = $id;
|
||||
$this->amount = $amount;
|
||||
$this->created = $created;
|
||||
$this->status = $status;
|
||||
$this->client_secret = $client_secret;
|
||||
$this->currency = strtoupper( $currency );
|
||||
$this->next_action = $next_action;
|
||||
$this->last_payment_error = $last_payment_error;
|
||||
$this->customer_id = $customer_id;
|
||||
$this->payment_method_id = $payment_method_id;
|
||||
$this->charge = $charge;
|
||||
$this->metadata = $metadata;
|
||||
$this->processing = $processing;
|
||||
$this->payment_method_types = $payment_method_types;
|
||||
$this->payment_method_options = $payment_method_options;
|
||||
$this->order = $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets charge amount
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_amount() {
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currency of this intention
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_currency() {
|
||||
return $this->currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last payment error of this intention
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_last_payment_error() {
|
||||
return $this->last_payment_error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the charge associated with this intention
|
||||
*
|
||||
* @return WC_Payments_API_Charge
|
||||
*/
|
||||
public function get_charge() {
|
||||
return $this->charge;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the processing state of this intention
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_processing() {
|
||||
return $this->processing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines which data will be serialized to JSON
|
||||
*/
|
||||
public function jsonSerialize(): array {
|
||||
return [
|
||||
'id' => $this->get_id(),
|
||||
'amount' => $this->get_amount(),
|
||||
'currency' => $this->get_currency(),
|
||||
'charge' => $this->get_charge(),
|
||||
'created' => $this->get_created()->getTimestamp(),
|
||||
'customer' => $this->get_customer_id(),
|
||||
'metadata' => $this->get_metadata(),
|
||||
'payment_method' => $this->get_payment_method_id(),
|
||||
'payment_method_types' => $this->get_payment_method_types(),
|
||||
'processing' => $this->get_processing(),
|
||||
'status' => $this->get_status(),
|
||||
'order' => $this->get_order(),
|
||||
];
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* WC_Payments_API_Setup_Intention class
|
||||
*
|
||||
* @package WooCommerce\Payments
|
||||
*/
|
||||
|
||||
/**
|
||||
* Setup Intent object used by the WooCommerce Payments API.
|
||||
*
|
||||
* Only add getters and properties existing in setup intent object https://stripe.com/docs/api/setup_intents/object.
|
||||
* Otherwise, add them in the (abstract) parent class.
|
||||
*/
|
||||
class WC_Payments_API_Setup_Intention extends WC_Payments_API_Abstract_Intention {
|
||||
/**
|
||||
* The last payment error of the intention
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $last_setup_error;
|
||||
|
||||
/**
|
||||
* WC_Payments_API_Setup_Intention constructor.
|
||||
*
|
||||
* @param string $id - ID of the intention.
|
||||
* @param string|null $customer_id - Stripe ID of the customer.
|
||||
* @param string|null $payment_method_id - Stripe ID of the payment method.
|
||||
* @param DateTime $created - Time charge created.
|
||||
* @param string $status - Intention status.
|
||||
* @param string $client_secret - The client secret of the intention.
|
||||
* @param array $next_action - An array containing information for next action to take.
|
||||
* @param array $last_setup_error - An array containing details of any errors.
|
||||
* @param array $metadata - An array containing additional metadata of associated charge or order.
|
||||
* @param array $payment_method_types - An array containing the possible payment methods for the intent.
|
||||
* @param array $payment_method_options - An array containing the payment method options for the intent.
|
||||
* @param array $order - An array containing the order data associated with this intention.
|
||||
*/
|
||||
public function __construct(
|
||||
string $id,
|
||||
?string $customer_id,
|
||||
?string $payment_method_id,
|
||||
DateTime $created,
|
||||
string $status,
|
||||
string $client_secret,
|
||||
array $next_action = [],
|
||||
array $last_setup_error = [],
|
||||
array $metadata = [],
|
||||
array $payment_method_types = [],
|
||||
array $payment_method_options = [],
|
||||
array $order = []
|
||||
) {
|
||||
$this->id = $id;
|
||||
$this->created = $created;
|
||||
$this->status = $status;
|
||||
$this->client_secret = $client_secret;
|
||||
$this->next_action = $next_action;
|
||||
$this->last_setup_error = $last_setup_error;
|
||||
$this->customer_id = $customer_id;
|
||||
$this->payment_method_id = $payment_method_id;
|
||||
$this->metadata = $metadata;
|
||||
$this->payment_method_types = $payment_method_types;
|
||||
$this->payment_method_options = $payment_method_options;
|
||||
$this->order = $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last payment error of this intention
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_last_setup_error(): array {
|
||||
return $this->last_setup_error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines which data will be serialized to JSON
|
||||
*/
|
||||
public function jsonSerialize(): array {
|
||||
return [
|
||||
'id' => $this->get_id(),
|
||||
'created' => $this->get_created()->getTimestamp(),
|
||||
'customer' => $this->get_customer_id(),
|
||||
'metadata' => $this->get_metadata(),
|
||||
'payment_method' => $this->get_payment_method_id(),
|
||||
'payment_method_types' => $this->get_payment_method_types(),
|
||||
'status' => $this->get_status(),
|
||||
'order' => $this->get_order(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user