WC_Gateway_Paypal_Request
in package
Generates requests to send to PayPal.
Table of Contents
- $endpoint : string
- Endpoint for requests to PayPal.
- $gateway : WC_Gateway_Paypal
- Pointer to gateway making the request.
- $line_items : array<string|int, mixed>
- Stores line items to send to PayPal.
- $notify_url : string
- Endpoint for requests from PayPal.
- __construct() : mixed
- Constructor.
- get_request_url() : string
- Get the PayPal request URL for an order.
- add_line_item() : mixed
- Add PayPal Line Item.
- currency_has_decimals() : bool
- Check if currency has decimals.
- delete_line_items() : mixed
- Remove all line items.
- fix_request_length() : array<string|int, mixed>
- If the default request with line items is too long, generate a new one with only one line item.
- get_line_item_args() : array<string|int, mixed>
- Get line item args for paypal request.
- get_line_item_args_single_item() : array<string|int, mixed>
- Get line item args for paypal request as a single line item.
- get_line_items() : mixed
- Return all line items.
- get_order_item_name() : string
- Get order item names as a string.
- get_order_item_names() : string
- Get order item names as a string.
- get_paypal_args() : array<string|int, mixed>
- Get PayPal Args for passing to PP.
- get_paypal_state() : string
- Get the state to send to paypal.
- get_phone_number_args() : array<string|int, mixed>
- Get phone number args for paypal request.
- get_shipping_args() : array<string|int, mixed>
- Get shipping args for paypal request.
- get_shipping_cost_line_item() : array<string|int, mixed>
- Get shipping cost line item args for paypal request.
- get_transaction_args() : array<string|int, mixed>
- Get transaction args for paypal request, except for line item args.
- limit_length() : string
- Limit length of an arg.
- line_items_valid() : bool
- Check if the order has valid line items to use for PayPal request.
- number_format() : string
- Format prices.
- prepare_line_items() : mixed
- Get line items to send to paypal.
- round() : float
- Round prices.
Properties
$endpoint
Endpoint for requests to PayPal.
protected
string
$endpoint
$gateway
Pointer to gateway making the request.
protected
WC_Gateway_Paypal
$gateway
$line_items
Stores line items to send to PayPal.
protected
array<string|int, mixed>
$line_items
= array()
$notify_url
Endpoint for requests from PayPal.
protected
string
$notify_url
Methods
__construct()
Constructor.
public
__construct(WC_Gateway_Paypal $gateway) : mixed
Parameters
- $gateway : WC_Gateway_Paypal
-
Paypal gateway object.
Return values
mixed —get_request_url()
Get the PayPal request URL for an order.
public
get_request_url(WC_Order $order[, bool $sandbox = false ]) : string
Parameters
- $order : WC_Order
-
Order object.
- $sandbox : bool = false
-
Whether to use sandbox mode or not.
Return values
string —add_line_item()
Add PayPal Line Item.
protected
add_line_item(string $item_name[, int $quantity = 1 ][, float $amount = 0.0 ][, string $item_number = '' ]) : mixed
Parameters
- $item_name : string
-
Item name.
- $quantity : int = 1
-
Item quantity.
- $amount : float = 0.0
-
Amount.
- $item_number : string = ''
-
Item number.
Return values
mixed —currency_has_decimals()
Check if currency has decimals.
protected
currency_has_decimals(string $currency) : bool
Parameters
- $currency : string
-
Currency to check.
Return values
bool —delete_line_items()
Remove all line items.
protected
delete_line_items() : mixed
Return values
mixed —fix_request_length()
If the default request with line items is too long, generate a new one with only one line item.
protected
fix_request_length(WC_Order $order, array<string|int, mixed> $paypal_args) : array<string|int, mixed>
If URL is longer than 2,083 chars, ignore line items and send cart to Paypal as a single item. One item's name can only be 127 characters long, so the URL should not be longer than limit. URL character limit via: https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
Parameters
- $order : WC_Order
-
Order to be sent to Paypal.
- $paypal_args : array<string|int, mixed>
-
Arguments sent to Paypal in the request.
Return values
array<string|int, mixed> —get_line_item_args()
Get line item args for paypal request.
protected
get_line_item_args(WC_Order $order[, bool $force_one_line_item = false ]) : array<string|int, mixed>
Parameters
- $order : WC_Order
-
Order object.
- $force_one_line_item : bool = false
-
Create only one item for this order.
Return values
array<string|int, mixed> —get_line_item_args_single_item()
Get line item args for paypal request as a single line item.
protected
get_line_item_args_single_item(WC_Order $order) : array<string|int, mixed>
Parameters
- $order : WC_Order
-
Order object.
Return values
array<string|int, mixed> —get_line_items()
Return all line items.
protected
get_line_items() : mixed
Return values
mixed —get_order_item_name()
Get order item names as a string.
protected
get_order_item_name(WC_Order $order, WC_Order_Item $item) : string
Parameters
- $order : WC_Order
-
Order object.
- $item : WC_Order_Item
-
Order item object.
Return values
string —get_order_item_names()
Get order item names as a string.
protected
get_order_item_names(WC_Order $order) : string
Parameters
- $order : WC_Order
-
Order object.
Return values
string —get_paypal_args()
Get PayPal Args for passing to PP.
protected
get_paypal_args(WC_Order $order) : array<string|int, mixed>
Parameters
- $order : WC_Order
-
Order object.
Return values
array<string|int, mixed> —get_paypal_state()
Get the state to send to paypal.
protected
get_paypal_state(string $cc, string $state) : string
Parameters
- $cc : string
-
Country two letter code.
- $state : string
-
State code.
Return values
string —get_phone_number_args()
Get phone number args for paypal request.
protected
get_phone_number_args(WC_Order $order) : array<string|int, mixed>
Parameters
- $order : WC_Order
-
Order object.
Return values
array<string|int, mixed> —get_shipping_args()
Get shipping args for paypal request.
protected
get_shipping_args(WC_Order $order) : array<string|int, mixed>
Parameters
- $order : WC_Order
-
Order object.
Return values
array<string|int, mixed> —get_shipping_cost_line_item()
Get shipping cost line item args for paypal request.
protected
get_shipping_cost_line_item(WC_Order $order, bool $force_one_line_item) : array<string|int, mixed>
Parameters
- $order : WC_Order
-
Order object.
- $force_one_line_item : bool
-
Whether one line item was forced by validation or URL length.
Return values
array<string|int, mixed> —get_transaction_args()
Get transaction args for paypal request, except for line item args.
protected
get_transaction_args(WC_Order $order) : array<string|int, mixed>
Parameters
- $order : WC_Order
-
Order object.
Return values
array<string|int, mixed> —limit_length()
Limit length of an arg.
protected
limit_length(string $string[, int $limit = 127 ]) : string
Parameters
- $string : string
-
Argument to limit.
- $limit : int = 127
-
Limit size in characters.
Return values
string —line_items_valid()
Check if the order has valid line items to use for PayPal request.
protected
line_items_valid(WC_Order $order) : bool
The line items are invalid in case of mismatch in totals or if any amount < 0.
Parameters
- $order : WC_Order
-
Order to be examined.
Return values
bool —number_format()
Format prices.
protected
number_format(float|int $price, WC_Order $order) : string
Parameters
- $price : float|int
-
Price to format.
- $order : WC_Order
-
Order object.
Return values
string —prepare_line_items()
Get line items to send to paypal.
protected
prepare_line_items(WC_Order $order) : mixed
Parameters
- $order : WC_Order
-
Order object.
Return values
mixed —round()
Round prices.
protected
round(float $price, WC_Order $order) : float
Parameters
- $price : float
-
Price to round.
- $order : WC_Order
-
Order object.