Skip to main content

Using Credit Card Charge Metadata for Custom Integrations in WeeConnectPay

Use exposed credit card charge metadata from WooCommerce orders for custom integrations. Postal code check example included.

Updated over 2 months ago

Overview
WeeConnectPay now provides a helper function that exposes credit card charge metadata saved on WooCommerce orders. This metadata is stored in the order meta under the key weeconnectpay_charges and includes the following keys:

  • charge_id

  • amount

  • currency

  • card_type

  • card_postal_code

  • status

This functionality enables custom third-party development by allowing developers to retrieve all relevant charge data for further processing, reporting, or validation. For example, you may compare the transaction postal code against the order’s billing or shipping postal code.


Available Helper Function

Function: WeeConnectPayHelper::getAllCreditCardCharges

Purpose:
Retrieves an array of all credit card charge metadata stored in the WooCommerce order. Each record contains:

  • charge_id: The unique identifier of the charge.

  • amount: The charge amount in cents.

  • currency: The currency code (e.g., CAD, USD).

  • card_type: The type of credit card used.

  • card_postal_code: The postal code provided during the card tokenization.

  • status: The status of the charge (e.g., "success", "refunded").

Currently, the implementation assumes that each order contains only one charge. Future enhancements will be necessary to support multiple charges (such as partial or split payments).

Usage Example:

// Retrieve all saved credit card charge metadata for a given order.
$charges = \WeeConnectPay\WordPress\Plugin\includes\WeeConnectPayHelper::getAllCreditCardCharges($order);
if (!empty($charges)) {
// Currently assuming only one charge exists per order.
$chargeData = $charges[0];

echo "Charge ID: " . $chargeData['charge_id'] . "\n";
echo "Amount: " . ($chargeData['amount'] / 100) . " " . $chargeData['currency'] . "\n";
echo "Card Type: " . $chargeData['card_type'] . "\n";
echo "Postal Code: " . $chargeData['card_postal_code'] . "\n";
echo "Status: " . $chargeData['status'] . "\n";
}


Example: Postal Code Validation

Below is an example of how developers can use the exposed metadata to perform custom validations. In this example, the transaction postal code (from the charge metadata) is compared with the order’s billing and shipping postal codes. Developers can then take any custom action if there is a mismatch.

Note: This postal code validation snippet is provided as an example only. In a real-world scenario, you may need to enhance the comparison logic to account for variations in postal code formats and differences in how they are stored across countries or websites. Consider this a starting point that might require additional adjustments before production use.

// Retrieve the credit card charge metadata.
$charges = \WeeConnectPay\WordPress\Plugin\includes\WeeConnectPayHelper::getAllCreditCardCharges($order);
if (!empty($charges)) {
// Assuming one charge exists per order.
$transactionPostalCode = $charges[0]['card_postal_code'];

// Retrieve the order's billing and shipping postal codes.
$billingPostalCode = $order->get_billing_postcode();
$shippingPostalCode = $order->get_shipping_postcode();

// Example validation: Check if the transaction postal code matches either billing or shipping postal code.
if ($transactionPostalCode !== $billingPostalCode && $transactionPostalCode !== $shippingPostalCode) {
// Developer may choose to flag the order or take other custom actions.
error_log("Postal code mismatch: Transaction postal code {$transactionPostalCode} does not match Billing ({$billingPostalCode}) or Shipping ({$shippingPostalCode}).");
}
}


Integration Key Points

  • Data Exposure:
    Use WeeConnectPayHelper::getAllCreditCardCharges($order) to retrieve all the stored charge metadata from an order.

  • Customization:
    Developers are free to use the retrieved metadata for various integrations, such as performing validations, generating custom reports, or triggering additional business logic.


This documentation explains how to expose and utilize credit card charge metadata within WooCommerce orders for custom integrations using WeeConnectPay. The postal code comparison is provided as an example of how this data can be leveraged for further validations.

Did this answer your question?