Skip to content

Latest commit

 

History

History
175 lines (117 loc) · 4.92 KB

customer-service.md

File metadata and controls

175 lines (117 loc) · 4.92 KB

WooCommerce Payments Core Customer Service

The customer service is available through the WC_Payments_Customer_Service_API class, available through WC_Payments::get_customer_service_api():

Example:

$payment_methods = WC_Payments::get_customer_service_api()->get_payment_methods_for_customer( 'cus_XXX', 'card' );

Available methods


get_customer_id_by_user_id()

Get WCPay customer ID for the given WordPress user ID

Parameters

  • $user_id (int) The user ID to look for a customer ID with.

Return value string? WCPay customer ID or null if not found.


create_customer_for_user()

Create a customer and associate it with a WordPress user.

Parameters

  • $user (WP_User) User to create a customer for.
  • $customer_data (array) Customer data.

Return value string The created customer's ID


update_customer_for_user()

Update the customer details held on the WCPay server associated with the given WordPress user.

Parameters

Return value string The updated customer's ID. Can be different to the ID parameter if the customer was re-created.


set_default_payment_method_for_customer()

Sets a payment method as default for a customer.

Parameters

  • $customer_id (string) The customer ID.
  • $payment_method_id (string) The payment method ID.

get_payment_methods_for_customer()

Gets all payment methods for a customer.

Parameters

  • $customer_id (string) The customer ID.
  • $type (string) Type of payment methods to fetch.

Return value array Payment methods.


update_payment_method_with_billing_details_from_order()

Updates a customer payment method.

Parameters

  • $payment_method_id (string) The payment method ID.
  • $order (WC_Order) Order to be used on the update.

Return value void This method does not return any value.


clear_cached_payment_methods_for_user()

Clear payment methods cache for a user.

Parameters

  • $user_id (int) WC user ID.

Return value void This method does not return any value.


map_customer_data()

Given a WC_Order or WC_Customer, returns an array representing a Stripe customer object.

At least one parameter has to not be null.

Parameters

  • $wc_order (WC_Order) The Woo order to parse.
  • $wc_customer (WC_Customer) The Woo customer to parse.

Return value array Customer data.

public static function map_customer_data( WC_Order $wc_order, WC_Customer $wc_customer )


delete_cached_payment_methods()

Delete all saved payment methods that are stored inside database cache driver.

Return value void This method does not return any value.


get_customer_id_for_order()

Get the WCPay customer ID associated with an order, or create one if none found.

Parameters

  • $order (WC_Order) WC Order object.

Return value string|null WCPay customer ID.


update_user_customer_id()

Updates the given user with the given WooCommerce Payments customer ID.

Parameters

  • $user_id (int) The WordPress user ID.
  • $customer_id (string) The WooCommerce Payments customer ID.

Return value void This method does not return any value.


add_customer_id_to_user()

Adds the WooComerce Payments customer ID found in the user session to the WordPress user as metadata.

Parameters

  • $user_id (int) The WordPress user ID.

Return value void This method does not return any value.


get_prepared_customer_data()

Prepares customer data to be used on 'Pay for Order' or 'Add Payment Method' pages.

  • Customer data is retrieved from order when on Pay for Order.
  • Customer data is retrieved from customer when on 'Add Payment Method'.

Return value array|null An array with customer data or nothing.