Product Checkout module

Learn more about the Product Checkout module.

The ProductCheckout module handles syncing data to the Digital River platform during the whole checkout process.

Specifications

This module is responsible for calculating the tax based on shipping address if available, or billing address if the shipping address is not available.

This module contains a Drop-in integration provided by Digital River for the checkout process. This includes legal content that is fetched from Digital River.js.

Customer checkouts can process from the US or from outside the US. If you will have customers with shipping addresses to the US, add a file uploader on the Checkout page for uploading tax certificates. If you will have customers with shipping addresses outside of the US, add a text field for adding the tax ID for the customer.

Pass the tax certificate

Complete the following tasks to pass the tax certificate.

  1. After order placement, pass the tax certificate to Digital River for verifications. Based on the verification, buyers will be notified whether or not their tax exemption certificate is valid.

  2. For the Input field tax ID, verify the tax ID during order placement.

  3. On the My Account page, create a section under the Account page for tax certificate verification. The buyer will see their tax certificate status.

  4. Create a Drop-in payment gateway for rendering payment options on the checkout page. The buyer will select the payment options, complete the necessary fields, and process the payment.

  5. After successful payment, pass all order instance data with customer data to Digital River API via the Drop-in gateway.

  6. Add a Save payment option for the Drop-in gateway to allow buyers to save their payment data for future purchases. Customers can process payments via Save Cards.

  7. Add the Save payment option on the My Account page so that customers can manage (add, update, remove, and save) their card and save payment options.

Hide others' default gateway from the customer checkout end when the Digital River gateway is enabled. Show a message in Admin Payment tab settings that other gateways are not showing either they are enabled.

Naming Conventions

For naming conventions:

  1. On the Checkout page, add two fields depending on customer billing or shipping country chosen.

    • Tax Certificate

      • Type: File field

      • Description: Enter your tax certificate

      • id/key: dr_customer_tax_certificate

      • Condition: Showing only if Shipping country is in the US

    • Tax ID

      • Type: number fields

      • Description: Enter your tax id number

      • id/key: dr_customer_tax_id_number

      • Condition: Showing only if shipping country is outside of the US

  2. On the My Account page, add a tax details section.

Product Checkout Methods

Product Checkout class

The class describes the module's entry point.

Method

Args, Return, and Description

name

Args: -

Return: string

Description: Returns the name of the module

__construct

Args: CheckoutContainer $container, Path: Settings $settings

/src/Modules/ProductCheckout/CheckoutContainer.php Args: TaxExemption $tax_exemption Path: /src/Modules/ProductCheckout/TaxExemption.php Args: CustomerMyAccount $customer_myaccount Path: /src/Modules/ProductCheckout/CustomerMyAccount.php

Return: void

Description: Initializes the object by passing in dependencies

init

Args: - Return: void

Description: Initializes the module, register necessary hooks, and call certain methods to complete the setup

render_gateway_class

Args: array $gateways

Return: array

Description: Adds the DropIn class to the list of gateways

hide_default_gateways

Args: array $gateways

Return: array

Description: Remove all gateways other than Digital River if the plugin is enabled.

show_gateway_message

Args: -

Return: void

Description: Displays a message on the payment gateway settings page that if the Digital River gateway is activated, other payment methods will be hidden from checkout.

add_to_cart_redirect

Args: String $url, int $product_id

Return: String

Description: Returns add to cart redirect URL

Drop-in class

This gateway class will be added to the list of supported payment gateways from the ProductCheckout class.

Method

Args, Return, and Description

__construct

Args: -

Return: void

Description: Constructs the object

init

Args: -

Return: void

Description: Sets Payment gateway title, description, and enqueue payment scripts by calling the payment_scripts() method

payment_scripts

Args: -

Return: void

Description: Enqueue necessary scripts on the Cart and Checkout page only if the plugin is enabled and the API keys are set.

payment_fields

Args: -

Return: void

Description: Render the payment fields

process_payment

Args: int $order_id

Return: void

Description: Processes the order after final payment

Tax Exemption class

This class adds Tax exemption fields to the Checkout page.

Method

Args and Return

__construct

Args: File $file_dr_handler

Return: void

init

Args: -

Return: void

tax_identifier_types

Args: String $country

Return: array

tax_authority_data

Args: -

Return: array

assets

Args: -

Return: void

Customer My Account class

This class handles adding a new subpage to the user's My Account page where the payment sources of a user can be viewed.

Method

Args, Return, and Description

__construct

Args: Settings $settingsCustomerHandler $customer_handlerTaxExemption $tax_exemptionFile $file_dr_handler

Return: void

Description: Constructs the object by passing in dependencies

init

Args: -

Return: void

Description: Registers necessary hooks

add_myaccount_endpoint

Args: -

Return: void

Description: Adds a new rewrite endpoint /dr-payments

add_query_vars

Args: array

Return: array

Description: Adds the dr-payments to the list of query variables

myaccount_scripts

Args: -

Return: void

Description: Load scripts only on the My Account page if the plugin is enabled and API Keys are set

endpoint_title

Args: String $title

Return: String

Description: Sets the title for the My Account page and subpages

dr_payment_link

Args: array $menu_links

Return: array

Description: Adds a new link 'Tax and Payments' to the My Account menu links ($menu_links) and returns the array

dr_payment_content

Args: -

Return: void

Description: Renders content callback for when the link /dr-payments is visited

get_sources

Args: Customer $dr_customer

Return: array

Description: Returns an array containing the payment sources of the customer with the default source placed as the first element

handle_payment_methods

Args: -

Return: void

Description: Handles payment method operations

create_customer_source

Args: -

Return: void

Description: Gets customer_id and source_id from the $_POST data and attach the source to the customer for future use

Customer Handler class

This class creates required data for a customer by using the Customer Digital River Handler class.

Method

Args, Returns, and Descriptions

__construct

Arg: TaxExemption $tax_exemption, Customer $customer_dr_handler, CheckoutUtils $checkout_utils

Return: void

Description: Constructs the object by passing in dependencies

create_dr_customer_from_postdata

Arg: -

Return: void

Description: Creates customer on Digital River from parsed post data sent by WooCommerce

create_dr_customer

Arg: array $data

Return: Customer

Description: Creates customer on Digital River from parameters. Returns theCustomer object and throws Exception if the data is invalid

fetch_dr_customer

Arg: string $id

Return: Customer

Description: Fetches customer from Digital River

Returns Customer object and throws Exception if the data is invalid

create_dr_customer_source

Arg: string $source_id

Return: Source

Description: Creates customer source on Digital River. Returns the Source if API is successful, throws Exception if the data is invalid

compare_customer_data

Arg: array $data

Return: Customer/null

Description: Compares customer data to check whether the customer needs an update. Returns the Customer object if it needs an update or is null

dr_customer_object

Arg: String $action, Customer $customer

Return: Customer/null

Description: Gets, saves, and deletes the Digital River customer object from the usermeta/wc session based on the user login status. Returns retrieved Customer object, or null

Checkout Handler class

This class creates required data for checkout by using the Checkout Digital River Handler class.

Method

Args, Returns, and Descriptions

__construct

Args:

CustomerHandler $customer_handler, TaxExemption $tax_exemption, Source $source_dr_handler, CheckoutUtils $checkout_utils

Return: void

Description: Construct the object by passing in dependencies

init

Arg: - Return: void

Description: Register necessary hooks

render_checkout_submit

Arg: -

Return: void

Description: Adds tax exemption fields on the checkout page

render_customer_type_option

Arg: -

Return: void

Description: Appends customer type option in checkout billing fields

woocommerce_cart_shipping_method_full_label

Arg: string $label, WC_Shipping_Rate $method

Return: String

Description: Callback for woocommerce_cart_shipping_method_full_label filter used to display the tax information

update_wc_order_data

Arg: WC_Order $order

Return: void

Description: Modifies WooCommerce order data and save according to Digital River checkout

replace_wc_order_details

Arg: array $total_rows, WC_Order $order, String $tax_display

Return: array

Description: Shows Digital River checkout total on order details

dr_product_subtotal

Arg: String $subtotal, Object $item, WC_Order $order

Return: String

Description: Shows the item total according to digitalriver checkout

validate_order_data

Arg: $default_value

Return: mixed

Description: Filters before creating Woocommerce order. Checks whether checkout object is stored in session and contains the source and customer ID

replace_checkout_order_review_template

Arg: array $fragments

Return: array

Description: Modifies order review table HTML contents to show Digital River's calculated taxes

assets

Arg: -

Return: void

Description: Enqueues the necessary scripts and stylesheets

process_checkout

Arg: -

Return: void

Description: Processes checkout, creates customer and returns calculated tax

handle_update_checkout_with_payment_source

Arg: -

Return: void

Description: Handles update checkout with payment source identifier ajax request

handle_update_source_checkout

Arg: -

Return: void

Description: Updates checkout with source ID if the billing address has changed

handle_checkout_get_payment_session_id

Arg: -

Return: void

Description: Handles get checkout payment session ID ajax request

include_templates

Arg: -

Return: void

Description: Includes WordPress templates in the footer

Compliance class

This class responsible for displaying the legal information from Digital River on the Cart, Checkout, and Thank You pages in WooCommerce.

Only the _construct method for this class has an arg.

Method

Returns and Descriptions

__construct

Return: void

Description: Construct the object by passing in dependencies

init

Return: void

Description: Registers necessary hooks

assets

Return: void

Description: Loads compliance scripts and stylesheets for rendering legal content on the store

show_compliance

Return: void

Description: Renders Digital River compliance message

prepare_checkout_request

Return: array

Description: Prepares request data for checkout

Digital River Handlers/checkout class

Method

Args, Returns, and Descriptions

get

Args: string $checkout_id

Return: Checkout

Description: Retrieves a checkout API call to Digital River, returns the Checkout object on success throws Exception for invalid data, or if API throws an error

update

Args: array $data

Return: Checkout

Description: Updates a checkout API call to Digital River and returns Checkout object on success throws Exception for invalid data, or if API throws an error

delete

Args: Checkout $checkout

Return: Checkout

Description: Deletes a checkout API call to Digital River and returns Checkout object on success throws Exception for invalid data, or if API throws an error

Digital River Handlers\Customer class

Method

Args, Returns, and Descriptions

get

Args: string $checkout_id

Return: Customer

Description: Retrieves a customer API call to Digital River, returns Customer object on success throws Exception for invalid data, or if the API throws an error.

create

Args: array $data

Return: Customer

Description: Creates a customer API call to Digital River and returns theCustomer object on success throws Exception for invalid data, or if the API throws an error.

update

Args: array $data

Return: Customer

Description: Updates a customer API call to Digital River, returns Customer object on success throws Exception for invalid data or if the API throws an error

delete

Args: string $customer_id

Return: Customer

Description: Deletes a customer API call to Digital River, returns the deleted Customer object on success throws Exception for invalid data, or if the API throws an error.

create_source

Args: string $customer_id, string $customer_id

Return: Source

Description: Creates a Customer Source API call to Digital River, returns Source object if API is successful, throws Exception for invalid data, or if the API throws an error.

delete_source

Args: string $customer_id, string $customer_id

Return: Source

Description: Deletes a Customer Source API call to Digital River, returns the deleted Source object if API is successful, throws Exception for invalid data, or if the API throws an error.

get_tax_certificate

Args: array $data

Return: TaxCertificate/null

Description: Retrieves tax certificate data from the data array and returns new TaxCertificate object

Digital River Handlers\File class

Method

Args, Returns, and Descriptions

create

Args: String $file, String $purpose

Return: File

Description: Creates a File API call to Digital River platform and returns File object if API is successful or throws an Exception

get

Args: String $file

Return: File

Description: Retrieves File API call to Digital River and returns File object on success throws Exception for invalid data, or if the API throws an error.

delete

Args: String $file

Return: File

Description: Deletes File API call to Digital River and returns the deleted File object on success throws Exception for invalid data, or if the API throws an error.

create_file_link

Args: String $file

Return: File

Description: Creates file link for file object for download and view and returns a FileLink object if API is successful, else false.

Digital River Handlers\Source class

Method

Args, Returns, and Descriptions

get

Args: String $source_id

Return: Source

Description: Makes retrieve Source API call to Digital River and returns Source object on success throws Exception for invalid data or if API throws an error.

Checkout Container class

This class acts as a Dependency Injection container for providing dependencies to classes present in the ProductCheckout module.

Method

Args, Returns, and Descriptions

__construct

Args: PimpleContainer

Return: void

Description: Accepts a Dependency Injection container as an argument and assigns it to a container attribute

define_services

Args: -

Return: void

Description: Defines all the classes present within the module

Last updated