### Install PayPal PHP Server SDK via Composer Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/README.md Installs the PayPal PHP Server SDK version 2.1.0 using Composer. This command adds the SDK as a dependency to your project's composer.json file. ```bash composer require "paypal/paypal-server-sdk:2.1.0" ``` -------------------------------- ### Setup Token Request JSON Example Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/models/setup-token-request.md This JSON structure represents a 'SetupTokenRequest', used to initiate a request for a setup token. It includes customer details and various payment source options like card, PayPal, Venmo, and Apple Pay. This request is crucial for vaulting payment instruments. ```json { "customer": { "id": "id0", "merchant_customer_id": "merchant_customer_id2" }, "payment_source": { "card": { "name": "name6", "number": "number6", "expiry": "expiry4", "security_code": "security_code8", "brand": "CB_NATIONALE" }, "paypal": { "description": "description2", "usage_pattern": "THRESHOLD_PREPAID", "shipping": { "name": { "full_name": "full_name6" }, "email_address": "email_address2", "phone_number": { "country_code": "country_code2", "national_number": "national_number6" }, "type": "SHIPPING", "address": { "address_line_1": "address_line_16", "address_line_2": "address_line_26", "admin_area_2": "admin_area_20", "admin_area_1": "admin_area_12", "postal_code": "postal_code8", "country_code": "country_code6" } }, "permit_multiple_payment_tokens": false, "usage_type": "MERCHANT" }, "venmo": { "description": "description6", "usage_pattern": "UNSCHEDULED_PREPAID", "shipping": { "name": { "full_name": "full_name6" }, "email_address": "email_address2", "phone_number": { "country_code": "country_code2", "national_number": "national_number6" }, "type": "SHIPPING", "address": { "address_line_1": "address_line_16", "address_line_2": "address_line_26", "admin_area_2": "admin_area_20", "admin_area_1": "admin_area_12", "postal_code": "postal_code8", "country_code": "country_code6" } }, "permit_multiple_payment_tokens": false, "usage_type": "MERCHANT" }, "apple_pay": { "token": "token6", "card": { "type": "UNKNOWN", "brand": "CB_NATIONALE", "billing_address": { "address_line_1": "address_line_12", "address_line_2": "address_line_28", "admin_area_2": "admin_area_28", "admin_area_1": "admin_area_14", "postal_code": "postal_code0", "country_code": "country_code8" } } }, "token": { "id": "id6", "type": "SETUP_TOKEN" } } } ``` -------------------------------- ### SetupTokenResponse JSON Example Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/models/setup-token-response.md This is a JSON representation of the SetupTokenResponse, illustrating the structure and data fields for a cached setup token. It includes details about the payment source, customer information, and associated links. ```json { "status": "CREATED", "id": "id6", "customer": { "id": "id0", "merchant_customer_id": "merchant_customer_id2" }, "payment_source": { "card": { "name": "name6", "last_digits": "last_digits0", "brand": "CB_NATIONALE", "expiry": "expiry4", "billing_address": { "address_line_1": "address_line_12", "address_line_2": "address_line_28", "admin_area_2": "admin_area_28", "admin_area_1": "admin_area_14", "postal_code": "postal_code0", "country_code": "country_code8" } }, "paypal": { "description": "description2", "usage_pattern": "THRESHOLD_PREPAID", "shipping": { "name": { "full_name": "full_name6" }, "email_address": "email_address2", "phone_number": { "country_code": "country_code2", "national_number": "national_number6" }, "type": "SHIPPING", "address": { "address_line_1": "address_line_16", "address_line_2": "address_line_26", "admin_area_2": "admin_area_20", "admin_area_1": "admin_area_12", "postal_code": "postal_code8", "country_code": "country_code6" } }, "permit_multiple_payment_tokens": false, "usage_type": "MERCHANT" }, "venmo": { "description": "description6", "usage_pattern": "UNSCHEDULED_PREPAID", "shipping": { "name": { "full_name": "full_name6" }, "email_address": "email_address2", "phone_number": { "country_code": "country_code2", "national_number": "national_number6" }, "type": "SHIPPING", "address": { "address_line_1": "address_line_16", "address_line_2": "address_line_26", "admin_area_2": "admin_area_20", "admin_area_1": "admin_area_12", "postal_code": "postal_code8", "country_code": "country_code6" } }, "permit_multiple_payment_tokens": false, "usage_type": "MERCHANT" } }, "links": [ { "href": "href6", "rel": "rel0", "method": "HEAD" } ] } ``` -------------------------------- ### SetupTokenResponseCard JSON Example Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/models/setup-token-response-card.md This snippet shows an example of the SetupTokenResponseCard structure as a JSON object. It includes fields like name, last_digits, brand, expiry, and billing_address, demonstrating how card information can be represented. ```json { "name": "name8", "last_digits": "last_digits2", "brand": "DISCOVER", "expiry": "expiry6", "billing_address": { "address_line_1": "address_line_12", "address_line_2": "address_line_28", "admin_area_2": "admin_area_28", "admin_area_1": "admin_area_14", "postal_code": "postal_code0", "country_code": "country_code8" } } ``` -------------------------------- ### Create Setup Token Source: https://context7.com/paypal/paypal-php-server-sdk/llms.txt Creates a setup token for initiating a payment transaction or vaulting a payment method. ```APIDOC ## Create Setup Token ### Description Creates a setup token for initiating a payment transaction or vaulting a payment method. This token is used to facilitate the approval process for the customer. ### Method POST (implied by SDK usage, actual HTTP method may vary) ### Endpoint /vault/setup-tokens (inferred from SDK context) ### Parameters #### Request Body - **body** (object) - Required - The request payload containing setup token details. - **customerId** (string) - Required - The ID of the customer for whom the setup token is being created. - **paymentSource** (object) - Required - Details of the payment source. - **card** (object) - Required if payment source is a card. - **number** (string) - Required - The card number. - **expiry** (string) - Required - The expiry date of the card in YYYY-MM format. - **securityCode** (string) - Required - The CVV or security code. - **paypalRequestId** (string) - Optional - A unique identifier for the PayPal request, used for idempotency. ### Request Example ```json { "body": { "paymentSource": { "card": { "number": "4032039658933480", "expiry": "2025-12", "securityCode": "123" } }, "customerId": "customer_4cb4e6c1" }, "paypalRequestId": "setup-token-example" } ``` ### Response #### Success Response (200 or 201) - **id** (string) - The unique identifier for the setup token. - **status** (string) - The current status of the setup token (e.g., CREATED, APPROVED). - **links** (array) - An array of links related to the setup token. - **href** (string) - The URL for the link. - **rel** (string) - The relationship of the link (e.g., 'approve'). #### Response Example ```json { "id": "st_abc123", "status": "CREATED", "links": [ { "href": "https://www.paypal.com/checkoutnow?token=st_abc123", "rel": "approve", "method": "GET" } ] } ``` ``` -------------------------------- ### Create Setup Token for Payment with PayPal PHP SDK Source: https://context7.com/paypal/paypal-php-server-sdk/llms.txt This function creates a setup token required for initiating a payment flow, particularly for recurring billing or stored payment methods. It uses builders to construct the request, including card details and customer ID. The output includes the setup token ID, its status, and an approval URL for the user to complete the payment. ```php getVaultController(); try { $collect = [ 'body' => SetupTokenRequestBuilder::init( SetupTokenRequestPaymentSourceBuilder::init() ->card( CardRequestBuilder::init() ->number('4032039658933480') ->expiry('2025-12') ->securityCode('123') ->build() ) ->build() ) ->customerId('customer_4cb4e6c1') ->build(), 'paypalRequestId' => 'setup-token-' . uniqid() ]; $apiResponse = $vaultController->createSetupToken($collect); $setupToken = $apiResponse->getResult(); echo "Setup Token ID: " . $setupToken->getId() . "\n"; echo "Status: " . $setupToken->getStatus() . "\n"; if ($setupToken->getLinks()) { foreach ($setupToken->getLinks() as $link) { if ($link->getRel() === 'approve') { echo "Approval URL: " . $link->getHref() . "\n"; } } } } catch (Exception $e) { echo "Error creating setup token: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### PaypalWalletCustomer JSON Example Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/models/paypal-wallet-customer.md An example of the PaypalWalletCustomer object represented in JSON format. This shows the structure for fields like id, email_address, phone, name, and merchant_customer_id. ```json { "id": "id8", "email_address": "email_address4", "phone": { "phone_type": "OTHER", "phone_number": { "national_number": "national_number6" } }, "name": { "given_name": "given_name2", "surname": "surname8" }, "merchant_customer_id": "merchant_customer_id0" } ``` -------------------------------- ### Payment Request JSON Example Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/models/paypal-payment-token.md An example JSON payload for a payment request, demonstrating the structure and fields required. ```APIDOC ## Payment Request JSON Example ### Description This is an example JSON object representing a payment request, illustrating the expected structure for fields like shipping details, usage patterns, and payment token permits. ### Method N/A (Data Structure Example) ### Endpoint N/A ### Parameters N/A (This is a request body example) ### Request Example ```json { "permit_multiple_payment_tokens": false, "description": "description6", "usage_pattern": "RECURRING_PREPAID", "shipping": { "name": { "full_name": "full_name6" }, "email_address": "email_address2", "phone_number": { "country_code": "country_code2", "national_number": "national_number6" }, "type": "SHIPPING", "address": { "address_line_1": "address_line_16", "address_line_2": "address_line_26", "admin_area_2": "admin_area_20", "admin_area_1": "admin_area_12", "postal_code": "postal_code8", "country_code": "country_code6" } }, "usage_type": "MERCHANT" } ``` ### Response N/A (This is a request body example) ``` -------------------------------- ### Example JSON Structure Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/models/paypal-payment-token.md An example JSON object demonstrating a common structure for PayPal transactions, including details about permits, descriptions, usage patterns, shipping information, and usage types. ```json { "permit_multiple_payment_tokens": false, "description": "description6", "usage_pattern": "RECURRING_PREPAID", "shipping": { "name": { "full_name": "full_name6" }, "email_address": "email_address2", "phone_number": { "country_code": "country_code2", "national_number": "national_number6" }, "type": "SHIPPING", "address": { "address_line_1": "address_line_16", "address_line_2": "address_line_26", "admin_area_2": "admin_area_20", "admin_area_1": "admin_area_12", "postal_code": "postal_code8", "country_code": "country_code6" } }, "usage_type": "MERCHANT" } ``` -------------------------------- ### Activate Subscription Request JSON Example Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/models/activate-subscription-request.md An example of the ActivateSubscriptionRequest structure represented as JSON. This demonstrates the expected format for the 'reason' field when activating a subscription. ```json { "reason": "reason4" } ``` -------------------------------- ### Client Initialization Source: https://context7.com/paypal/paypal-php-server-sdk/llms.txt Sets up the PayPal client with authentication credentials, environment, and logging configurations. ```APIDOC ## Client Initialization ### Description Initializes the PayPal client with OAuth 2.0 Client Credentials authentication, specifying the environment (sandbox or live), and configuring retry mechanisms and logging. ### Method Not applicable (Client Setup) ### Endpoint Not applicable (Client Setup) ### Parameters #### Request Body * **clientCredentialsAuthCredentials** (object) - Required - Credentials for OAuth 2.0 Client Credentials authentication. * **clientId** (string) - Required - Your PayPal application's Client ID. * **clientSecret** (string) - Required - Your PayPal application's Client Secret. * **environment** (string) - Required - The PayPal environment to use (e.g., `Environment::SANDBOX`, `Environment::LIVE`). * **timeout** (integer) - Optional - The request timeout in seconds. * **enableRetries** (boolean) - Optional - Whether to enable automatic retries for failed requests. * **numberOfRetries** (integer) - Optional - The number of retries to attempt if `enableRetries` is true. * **retryInterval** (integer) - Optional - The interval in seconds between retries. * **loggingConfiguration** (object) - Optional - Configuration for request and response logging. * **level** (string) - Required - The logging level (e.g., `LogLevel::INFO`). * **requestConfiguration** (object) - Optional - Configuration for logging request details. * **body** (boolean) - Optional - Whether to log the request body. * **responseConfiguration** (object) - Optional - Configuration for logging response details. * **headers** (boolean) - Optional - Whether to log the response headers. ### Request Example ```php clientCredentialsAuthCredentials( ClientCredentialsAuthCredentialsBuilder::init( 'YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET' ) ) ->environment(Environment::SANDBOX) ->timeout(30) ->enableRetries(true) ->numberOfRetries(3) ->retryInterval(1) ->loggingConfiguration( LoggingConfigurationBuilder::init() ->level(LogLevel::INFO) ->requestConfiguration(RequestLoggingConfigurationBuilder::init()->body(true)) ->responseConfiguration(ResponseLoggingConfigurationBuilder::init()->headers(true)) ) ->build(); ``` ### Response #### Success Response (200) Returns an initialized `PaypalServerSdkClient` object. #### Response Example Not applicable (Client Setup) ``` -------------------------------- ### Get Credit Term - PayPal PHP SDK Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/models/transaction-information.md Retrieves the credit term associated with installment payments. Returns a string or null. The term specifies the length and unit of the installment period. ```php public function getCreditTerm(): ?string ``` -------------------------------- ### Get Setup Token using PHP Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/controllers/vault.md Retrieves a Setup Token based on its ID. This function requires a Setup Token ID as a string and returns an ApiResponse. The response data is a SetupTokenResponse object. Potential errors include invalid IDs or server-side issues. ```php $id = 'id0'; $apiResponse = $vaultController->getSetupToken($id); ``` -------------------------------- ### Example JSON Configuration for PayPal SDK Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/models/order-application-context.md Provides a sample JSON object illustrating the structure for configuring PayPal SDK settings, including landing page preference, shipping preference, user action, brand name, and locale. ```json { "landing_page": "NO_PREFERENCE", "shipping_preference": "GET_FROM_FILE", "user_action": "CONTINUE", "brand_name": "brand_name2", "locale": "locale6" } ``` -------------------------------- ### Initialize PayPal Client with Authentication and Logging Source: https://context7.com/paypal/paypal-php-server-sdk/llms.txt Sets up the PayPal client using OAuth 2.0 Client Credentials authentication. It configures the environment to SANDBOX, sets a request timeout, enables retries with specified intervals, and configures logging for requests and responses. ```php clientCredentialsAuthCredentials( ClientCredentialsAuthCredentialsBuilder::init( 'YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET' ) ) ->environment(Environment::SANDBOX) ->timeout(30) ->enableRetries(true) ->numberOfRetries(3) ->retryInterval(1) ->loggingConfiguration( LoggingConfigurationBuilder::init() ->level(LogLevel::INFO) ->requestConfiguration(RequestLoggingConfigurationBuilder::init()->body(true)) ->responseConfiguration(ResponseLoggingConfigurationBuilder::init()->headers(true)) ) ->build(); ``` -------------------------------- ### List Subscriptions PHP Example Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/controllers/subscriptions.md Demonstrates how to list subscriptions using the PayPal PHP Server SDK. It shows how to set pagination parameters like pageSize and page to retrieve subscription data. ```php $collect = [ 'pageSize' => 10, 'page' => 1 ]; $apiResponse = $subscriptionsController->listSubscriptions($collect); ``` -------------------------------- ### Billing Cycle JSON Example Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/models/billing-cycle.md This snippet shows an example of how a BillingCycle object is represented in JSON format. It includes details like tenure type, total cycles, sequence, pricing scheme, and start date. ```json { "tenure_type": "REGULAR", "total_cycles": 1, "sequence": 1, "pricing_scheme": { "price": { "currency_code": "currency_code8", "value": "value4" }, "pricing_model": "AUTO_RELOAD", "reload_threshold_amount": { "currency_code": "currency_code0", "value": "value6" } }, "start_date": "start_date0" } ``` -------------------------------- ### GET /vault/setup-token/{id} Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/controllers/vault.md Retrieves a readable representation of a temporarily vaulted payment source associated with the setup token ID. ```APIDOC ## Get Setup Token Returns a readable representation of temporarily vaulted payment source associated with the setup token id. ### Method GET ### Endpoint `/vault/setup-token/{id}` ### Parameters #### Path Parameters - **id** (string) - Required - ID of the setup token. *Constraints*: Minimum Length: 7, Maximum Length: 36, Pattern: `^[0-9a-zA-Z_-]+$` ### Request Example ```json { "id": "id0" } ``` ### Response #### Success Response (200) - **SetupTokenResponse** - The response data containing details of the setup token. #### Response Example ```json { "result": { "id": "string", "customer": { "id": "string" }, "payment_source": { "token": "string" }, "links": [ { "href": "string", "rel": "string", "method": "string" } ] } } ``` ### Errors - 400: Request is not well-formed, syntactically incorrect, or violates schema. - 403: Authorization failed due to insufficient permissions. - 404: The specified resource does not exist. - 422: The requested action could not be performed, semantically incorrect, or failed business validation. - 500: An internal server error has occurred. ``` -------------------------------- ### Create PayPal Subscription Plan JSON Example Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/models/modify-subscription-response.md This JSON object represents a request to create a subscription plan with PayPal. It includes details such as plan ID, quantity, shipping information, billing cycles, pricing structures, and payment preferences. Ensure all currency codes and values are accurately set for your specific transaction. ```json { "plan_id": "plan_id6", "quantity": "quantity0", "shipping_amount": { "currency_code": "currency_code0", "value": "value6" }, "shipping_address": { "name": { "full_name": "full_name6" }, "email_address": "email_address8", "phone_number": { "country_code": "country_code2", "national_number": "national_number6" }, "type": "PICKUP_IN_STORE", "options": [ { "id": "id2", "label": "label2", "type": "SHIPPING", "amount": { "currency_code": "currency_code6", "value": "value0" }, "selected": false } ] }, "plan": { "billing_cycles": [ { "pricing_scheme": { "version": 10, "fixed_price": { "currency_code": "currency_code4", "value": "value0" }, "pricing_model": "VOLUME", "tiers": [ { "starting_quantity": "starting_quantity8", "ending_quantity": "ending_quantity6", "amount": { "currency_code": "currency_code6", "value": "value0" } }, { "starting_quantity": "starting_quantity8", "ending_quantity": "ending_quantity6", "amount": { "currency_code": "currency_code6", "value": "value0" } }, { "starting_quantity": "starting_quantity8", "ending_quantity": "ending_quantity6", "amount": { "currency_code": "currency_code6", "value": "value0" } } ], "create_time": "create_time4" }, "sequence": 8, "total_cycles": 198 }, { "pricing_scheme": { "version": 10, "fixed_price": { "currency_code": "currency_code4", "value": "value0" }, "pricing_model": "VOLUME", "tiers": [ { "starting_quantity": "starting_quantity8", "ending_quantity": "ending_quantity6", "amount": { "currency_code": "currency_code6", "value": "value0" } }, { "starting_quantity": "starting_quantity8", "ending_quantity": "ending_quantity6", "amount": { "currency_code": "currency_code6", "value": "value0" } }, { "starting_quantity": "starting_quantity8", "ending_quantity": "ending_quantity6", "amount": { "currency_code": "currency_code6", "value": "value0" } } ], "create_time": "create_time4" }, "sequence": 8, "total_cycles": 198 } ], "payment_preferences": { "auto_bill_outstanding": false, "setup_fee": { "currency_code": "currency_code8", "value": "value4" }, "setup_fee_failure_action": "CONTINUE", "payment_failure_threshold": 104 }, "taxes": { "percentage": "percentage8", "inclusive": false } } } ``` -------------------------------- ### Get Subscription by ID PHP Example Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/controllers/subscriptions.md Illustrates how to retrieve details for a specific subscription using its ID with the PayPal PHP Server SDK. The 'fields' parameter can be used to specify which details to return. ```php function getSubscription(array $options): ApiResponse { // Function implementation details } ``` -------------------------------- ### Fee Amount Getter and Setter in PHP Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/models/transaction-information.md This example illustrates how to get and set the fee amount, which is represented by the Money object. The getter returns an optional Money object, and the setter accepts an optional Money object. ```php getFeeAmount(); // Set the fee amount $monetary->setFeeAmount($money); ?> ``` -------------------------------- ### Add PayPal PHP Server SDK to composer.json Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/README.md Manually adds the PayPal PHP Server SDK version 2.1.0 to the 'require' section of your composer.json file. This ensures the SDK is included in your project dependencies. ```json { "require": { "paypal/paypal-server-sdk": "2.1.0" } } ``` -------------------------------- ### PayPal SDK Example Configuration (JSON) Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/models/venmo-payment-token.md This JSON object represents an example configuration for the PayPal PHP Server SDK. It includes details for payment token usage, description, shipping information, and usage type. Ensure all fields are correctly populated according to PayPal's API documentation. ```json { "permit_multiple_payment_tokens": false, "description": "description4", "usage_pattern": "INSTALLMENT_PREPAID", "shipping": { "name": { "full_name": "full_name6" }, "email_address": "email_address2", "phone_number": { "country_code": "country_code2", "national_number": "national_number6" }, "type": "SHIPPING", "address": { "address_line_1": "address_line_16", "address_line_2": "address_line_26", "admin_area_2": "admin_area_20", "admin_area_1": "admin_area_12", "postal_code": "postal_code8", "country_code": "country_code6" } }, "usage_type": "MERCHANT" } ``` -------------------------------- ### Sales Tax Amount Getter and Setter in PHP Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/models/transaction-information.md This example shows how to get and set the sales tax amount using the Money object. The getter returns an optional Money object, and the setter accepts an optional Money object. ```php getSalesTaxAmount(); // Set the sales tax amount $monetary->setSalesTaxAmount($money); ?> ``` -------------------------------- ### Transaction Initiation Date Getter and Setter in PHP Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/models/transaction-information.md This example demonstrates getting and setting the transaction initiation date. The date must be in RFC 3339 format. The getter returns an optional string, and the setter accepts an optional string. ```php getTransactionInitiationDate(); // Set the transaction initiation date (RFC 3339 format) $timing->setTransactionInitiationDate('2023-10-27T10:00:00Z'); ?> ``` -------------------------------- ### Paypal Wallet Experience Context Configuration Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/models/paypal-wallet-experience-context.md Configure the payer experience during PayPal payment approval. ```APIDOC ## POST /paypal/paypal-php-server-sdk/PaypalWalletExperienceContext ### Description This endpoint allows configuration of the payer experience during the approval process for payment with PayPal. Note: Partners and Marketplaces might configure brand_name and shipping_preference during partner account setup, which overrides the request values. ### Method POST ### Endpoint /paypal/paypal-php-server-sdk/PaypalWalletExperienceContext ### Parameters #### Request Body - **brandName** (string) - Optional - The label that overrides the business name in the PayPal account on the PayPal site. Supports Unicode. Constraints: Minimum Length: 1, Maximum Length: 127. - **locale** (string) - Optional - The language tag for the language in which to localize error-related strings. Constraints: Minimum Length: 2, Maximum Length: 10. - **shippingPreference** (string) - Optional - The location from which the shipping address is derived. Default: `PaypalWalletContextShippingPreference::GET_FROM_FILE`. Constraints: Minimum Length: 1, Maximum Length: 24. - **contactPreference** (string) - Optional - The preference to display the contact information on PayPal's checkout. Default: `PaypalWalletContactPreference::NO_CONTACT_INFO`. Constraints: Minimum Length: 1, Maximum Length: 24. - **returnUrl** (string) - Optional - Describes the URL. - **cancelUrl** (string) - Optional - Describes the URL. - **appSwitchContext** (object) - Optional - Merchant provided details of the native app or mobile web browser to facilitate buyer's app switch to the PayPal consumer app. - **landingPage** (string) - Optional - The type of landing page to show on the PayPal site for customer checkout. Default: `PaypalExperienceLandingPage::NO_PREFERENCE`. Constraints: Minimum Length: 1, Maximum Length: 13. - **userAction** (string) - Optional - Configures a Continue or Pay Now checkout flow. Default: `PaypalExperienceUserAction::CONTINUE_`. Constraints: Minimum Length: 1, Maximum Length: 8. - **paymentMethodPreference** (string) - Optional - The merchant-preferred payment methods. Default: `PayeePaymentMethodPreference::UNRESTRICTED`. Constraints: Minimum Length: 1, Maximum Length: 255. - **orderUpdateCallbackConfig** (object) - Optional - CallBack Configuration that the merchant can provide to PayPal/Venmo. ### Request Example ```json { "brandName": "YourBrandName", "locale": "en-US", "shippingPreference": "GET_FROM_FILE", "contactPreference": "NO_CONTACT_INFO", "returnUrl": "https://example.com/return", "cancelUrl": "https://example.com/cancel" } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message. #### Response Example ```json { "message": "Paypal wallet experience context configured successfully." } ``` ``` -------------------------------- ### Order Application Context User Action (Deprecated) Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/models/order-application-context-user-action.md Configures a Continue or Pay Now checkout flow. This feature is deprecated and users should now specify this in the `experience_context` object under the `payment_source`. ```APIDOC ## Order Application Context User Action (Deprecated) ### Description Configures a Continue or Pay Now checkout flow. The fields in `application_context` are now available in the `experience_context` object under the `payment_source` which supports them (eg. `payment_source.paypal.experience_context.user_action`). Please specify this field in the `experience_context` object instead of the `application_context` object. ### Method N/A (Configuration Enum) ### Endpoint N/A (Configuration Enum) ### Parameters N/A (Configuration Enum) ### Request Example N/A (Configuration Enum) ### Response N/A (Configuration Enum) ## Enumeration: OrderApplicationContextUserAction ### Fields * **`CONTINUE_`** (string) - After redirecting the customer to the PayPal payment page, a Continue button appears. Use this option when the final amount is not known when the checkout flow is initiated and you want to redirect the customer to the merchant page without processing the payment. * **`PAY_NOW`** (string) - After redirecting the customer to the PayPal payment page, a Pay Now button appears. Use this option when the final amount is known when the checkout is initiated and you want to process the payment immediately when the customer clicks Pay Now. ``` -------------------------------- ### One Time Charge JSON Example Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/models/one-time-charge.md This JSON object represents a one-time charge with details such as setup fee, shipping amount, taxes, product price, subtotal, and total amount. Each monetary value includes a currency code and its corresponding value. ```json { "setup_fee": { "currency_code": "currency_code8", "value": "value4" }, "shipping_amount": { "currency_code": "currency_code0", "value": "value6" }, "taxes": { "currency_code": "currency_code6", "value": "value2" }, "product_price": { "currency_code": "currency_code6", "value": "value2" }, "subtotal": { "currency_code": "currency_code2", "value": "value8" }, "total_amount": { "currency_code": "currency_code2", "value": "value8" } } ``` -------------------------------- ### Create PayPal Billing Plan in PHP Source: https://context7.com/paypal/paypal-php-server-sdk/llms.txt This snippet demonstrates how to create a billing plan using the PayPal PHP Server SDK. It defines the plan's details, including name, description, billing cycles, pricing, and payment preferences. Dependencies include various builder classes from the SDK. ```php getSubscriptionsController(); try { $collect = [ 'prefer' => 'return=representation', 'body' => PlanRequestBuilder::init( 'PROD-XXCD1234QWER65782', 'Premium Membership Plan', [ SubscriptionBillingCycleBuilder::init( FrequencyBuilder::init(IntervalUnit::MONTH) ->intervalCount(1) ->build(), TenureType::REGULAR, 1 ) ->pricingScheme( PricingSchemeBuilder::init() ->fixedPrice(MoneyBuilder::init('USD', '29.99')->build()) ->build() ) ->totalCycles(12) ->build() ], PaymentPreferencesBuilder::init() ->autoBillOutstanding(true) ->setupFeeFailureAction(SetupFeeFailureAction::CONTINUE) ->paymentFailureThreshold(3) ->build() ) ->description('Monthly premium subscription with full access') ->status(PlanRequestStatus::ACTIVE) ->build(), 'paypalRequestId' => 'plan-' . uniqid() ]; $apiResponse = $subscriptionsController->createBillingPlan($collect); $plan = $apiResponse->getResult(); echo "Plan ID: " . $plan->getId() . "\n"; echo "Plan Name: " . $plan->getName() . "\n"; echo "Status: " . $plan->getStatus() . "\n"; } catch (Exception $e) { echo "Error creating billing plan: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### Get Refund Details Example (PHP) Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/controllers/payments.md Shows how to retrieve details for a specific refund using the PayPal PHP Server SDK. This function requires a refund ID as input and returns an `ApiResponse` object. The SDK handles the necessary API calls and response parsing. ```php function getRefund(array $options): ApiResponse ``` -------------------------------- ### Initialize PayPal Server SDK Client with Client Credentials and Logging Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/client.md Initializes the PayPal Server SDK client using OAuth 2.0 Client Credentials Grant for authentication. It configures the API environment to SANDBOX and sets up detailed logging for requests and responses, including request bodies and response headers. This snippet demonstrates setting up the client with specific authentication and logging preferences. ```php use PaypalServerSdkLib\Logging\LoggingConfigurationBuilder; use PaypalServerSdkLib\Logging\RequestLoggingConfigurationBuilder; use PaypalServerSdkLib\Logging\ResponseLoggingConfigurationBuilder; use Psr\Log\LogLevel; use PaypalServerSdkLib\Environment; use PaypalServerSdkLib\Authentication\ClientCredentialsAuthCredentialsBuilder; use PaypalServerSdkLib\PaypalServerSdkClientBuilder; $client = PaypalServerSdkClientBuilder::init() ->clientCredentialsAuthCredentials( ClientCredentialsAuthCredentialsBuilder::init( 'OAuthClientId', 'OAuthClientSecret' ) ) ->environment(Environment::SANDBOX) ->loggingConfiguration( LoggingConfigurationBuilder::init() ->level(LogLevel::INFO) ->requestConfiguration(RequestLoggingConfigurationBuilder::init()->body(true)) ->responseConfiguration(ResponseLoggingConfigurationBuilder::init()->headers(true)) ) ->build(); ``` -------------------------------- ### Get Payment Authorization Details using PayPal PHP SDK Source: https://context7.com/paypal/paypal-php-server-sdk/llms.txt This example shows how to retrieve the details of an authorized PayPal payment using its authorization ID. It uses the `getAuthorizedPayment` method from the `PaymentsController` to fetch information such as the authorization ID, status, amount, creation time, and expiration time. The code includes error handling for potential issues. ```php getPaymentsController(); $authorizationId = '8AA831015G517922L'; try { $collect = [ 'authorizationId' => $authorizationId ]; $apiResponse = $paymentsController->getAuthorizedPayment($collect); $authorization = $apiResponse->getResult(); echo "Authorization ID: " . $authorization->getId() . "\n"; echo "Status: " . $authorization->getStatus() . "\n"; echo "Amount: " . $authorization->getAmount()->getValue() . " " . $authorization->getAmount()->getCurrencyCode() . "\n"; echo "Created: " . $authorization->getCreateTime() . "\n"; echo "Expires: " . $authorization->getExpirationTime() . "\n"; } catch (Exception $e) { echo "Error retrieving authorization: " . $e->getMessage() . "\n"; } ?> ``` -------------------------------- ### Example API Response Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/models/payments-capture.md An example of a JSON response structure, likely representing a payment or order resource. ```APIDOC ## Example API Response ### Description This is an example JSON object representing a successful API response, potentially for a payment or order. ### Response Example (200 OK) ```json { "final_capture": false, "disbursement_mode": "INSTANT", "status": "COMPLETED", "status_details": { "reason": "VERIFICATION_REQUIRED" }, "id": "id0", "amount": { "currency_code": "currency_code6", "value": "value0" }, "invoice_id": "invoice_id0" } ``` ``` -------------------------------- ### Activate Billing Plan using PayPal PHP Server SDK Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/controllers/subscriptions.md This code example shows how to activate a billing plan by its ID using the PayPal PHP Server SDK. It takes a string ID as input and returns an ApiResponse. Proper error handling for authentication, authorization, and resource existence is recommended. ```php $id = 'id0'; $apiResponse = $subscriptionsController->activateBillingPlan($id); ``` -------------------------------- ### SepaDebitExperienceContext Configuration (PHP) Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/models/sepa-debit-experience-context.md This snippet demonstrates how to set up the SepaDebitExperienceContext for SEPA Debit payments. It allows customization of the payer's experience by specifying the locale, return URL, and cancel URL. ```php setLocale('en-US'); // Example: English (United States) $sepaDebitContext->setReturnUrl('https://example.com/return'); $sepaDebitContext->setCancelUrl('https://example.com/cancel'); // You can then use $sepaDebitContext when creating a payment or transaction. ?> ``` -------------------------------- ### Define Card Experience Context with URLs (PHP) Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/models/card-experience-context.md Demonstrates how to define the CardExperienceContext in PHP, specifying return and cancel URLs for the 3DS approval process. This class is part of the PayPal PHP SDK and helps customize the payer's interaction. ```php setReturnUrl("https://example.com/return"); $cardExperienceContext->setCancelUrl("https://example.com/cancel"); // You can then use $cardExperienceContext in your payment creation process. ?> ``` -------------------------------- ### PhoneNumber JSON Structure Example Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/models/phone-number.md An example illustrating the JSON representation of a PhoneNumber object, highlighting the 'national_number' field. ```json { "national_number": "national_number8" } ``` -------------------------------- ### Order Application Context Landing Page (Deprecated) Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/models/order-application-context-landing-page.md The `OrderApplicationContextLandingPage` enumeration is deprecated. Use the `experience_context` object within the `payment_source` for similar functionality. ```APIDOC ## Order Application Context Landing Page (Deprecated) ### Description This enumeration specifies the type of landing page to display on the PayPal site during customer checkout. It is now deprecated. ### Method N/A (Enumeration) ### Endpoint N/A (Enumeration) ### Parameters This is an enumeration and does not have parameters in the traditional sense. The values represent different landing page preferences. ### Request Example N/A ### Response #### Success Response (N/A) N/A #### Response Example N/A ### Enumeration Values - `LOGIN`: Redirects the customer to a PayPal login page for payment approval. - `BILLING`: Redirects the customer to a page to enter credit/debit card and billing information. - `NO_PREFERENCE`: Redirects the customer based on their previous interaction with PayPal (login or billing page). ``` -------------------------------- ### PayPal Checkout Option Example (JSON) Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/models/item-details.md An example JSON object representing a checkout option for PayPal. This structure is typically used when configuring items or order details. ```json { "item_code": "item_code4", "item_name": "item_name2", "item_description": "item_description0", "item_options": "item_options4", "item_quantity": "item_quantity4" } ``` -------------------------------- ### Capture Payment Example (PHP) Source: https://github.com/paypal/paypal-php-server-sdk/blob/main/doc/controllers/payments.md Demonstrates how to capture a payment using the PayPal PHP Server SDK. This involves preparing a collection of parameters and calling the `getCapturedPayment` method on the payments controller. It does not specify dependencies beyond the SDK itself, and the output is an `ApiResponse` object. ```php $collect = [ 'captureId' => 'capture_id2' ]; $apiResponse = $paymentsController->getCapturedPayment($collect); ```