parses paypal soap logs

Compare changes

Choose any two refs to compare.

Changed files
+220 -147
.github
workflows
docs
src
+70
.github/workflows/release.yml
···
···
+
name: Build and Release
+
+
on:
+
push:
+
tags:
+
- 'v*'
+
+
jobs:
+
build:
+
name: Build on ${{ matrix.os }}
+
runs-on: ${{ matrix.os }}
+
permissions:
+
contents: read
+
strategy:
+
fail-fast: false
+
matrix:
+
include:
+
- os: ubuntu-latest
+
platform: x86_64-linux
+
- os: macos-latest
+
platform: x86_64-darwin
+
- os: macos-latest
+
platform: aarch64-darwin
+
extra_args: --option system aarch64-darwin
+
+
steps:
+
- name: Checkout code
+
uses: actions/checkout@v4
+
+
- name: Install Nix
+
uses: DeterminateSystems/determinate-nix-action@v3.11.2
+
+
- name: Build binary
+
run: |
+
if [[ "${{ matrix.platform }}" == *"-linux" ]]; then
+
# For Linux builds
+
nix build .#packages.${{ matrix.platform }}.default --option system ${{ matrix.platform }} -o result-${{ matrix.platform }}
+
else
+
# For macOS builds
+
nix build .#packages.${{ matrix.platform }}.default ${{ matrix.extra_args }} -o result-${{ matrix.platform }}
+
fi
+
mkdir -p dist
+
cp -r result-${{ matrix.platform }}/bin/* dist/
+
cd dist && tar -czf ../soapdump-${{ matrix.platform }}.tar.gz *
+
+
- name: Upload artifact
+
uses: actions/upload-artifact@v4
+
with:
+
name: soapdump-${{ matrix.platform }}
+
path: soapdump-${{ matrix.platform }}.tar.gz
+
+
release:
+
name: Create Release
+
needs: build
+
runs-on: ubuntu-latest
+
permissions:
+
contents: write
+
steps:
+
- name: Download all artifacts
+
uses: actions/download-artifact@v4
+
+
- name: Create Release
+
id: create_release
+
uses: softprops/action-gh-release@v1
+
with:
+
files: |
+
soapdump-x86_64-linux/soapdump-x86_64-linux.tar.gz
+
soapdump-x86_64-darwin/soapdump-x86_64-darwin.tar.gz
+
soapdump-aarch64-darwin/soapdump-aarch64-darwin.tar.gz
+
generate_release_notes: true
+17 -4
README.md
···
A high-performance PayPal SOAP log parser written in C++.
## Usage
```bash
···
### Installation
-
Install directly from the flake:
-
```bash
nix profile install github:taciturnaxolotl/soapdump
```
Or run without installing:
```bash
···
## Output Format
-
Tab-separated values with the following fields:
```
TRANS_NUM|AMOUNT|CURRENCY|FIRSTNAME|LASTNAME|STREET|CITY|STATE|ZIP|CCTYPE|CCLAST4|EXPMONTH|EXPYEAR|CVV|TRANSID|STATUS|CORRID|PROC_AMOUNT
···
<p align="center">
<a href="https://github.com/taciturnaxolotl/soapdump/blob/main/LICENSE.md"><img src="https://img.shields.io/static/v1.svg?style=for-the-badge&label=License&message=MIT&logoColor=d9e0ee&colorA=363a4f&colorB=b7bdf8"/></a>
-
</p>
···
A high-performance PayPal SOAP log parser written in C++.
+
![gif of the program in action](https://github.com/taciturnaxolotl/soapdump/blob/main/docs/vhs.gif)
+
## Usage
```bash
···
### Installation
```bash
nix profile install github:taciturnaxolotl/soapdump
```
+
or in the flake:
+
+
```nix
+
{
+
inputs.soapdump.url = "github:taciturnaxolotl/soapdump";
+
+
outputs = { self, nixpkgs, soapdump, ... }: {
+
# Access the package as:
+
# soapdump.packages.${system}.default
+
};
+
}
+
```
+
Or run without installing:
```bash
···
## Output Format
+
Pipe-separated values with the following fields:
```
TRANS_NUM|AMOUNT|CURRENCY|FIRSTNAME|LASTNAME|STREET|CITY|STATE|ZIP|CCTYPE|CCLAST4|EXPMONTH|EXPYEAR|CVV|TRANSID|STATUS|CORRID|PROC_AMOUNT
···
<p align="center">
<a href="https://github.com/taciturnaxolotl/soapdump/blob/main/LICENSE.md"><img src="https://img.shields.io/static/v1.svg?style=for-the-badge&label=License&message=MIT&logoColor=d9e0ee&colorA=363a4f&colorB=b7bdf8"/></a>
+
</p>
+28
cassette.tape
···
···
+
Output docs/vhs.gif
+
Set Shell zsh
+
Sleep 1s
+
Type "soapdump -h"
+
Enter
+
Sleep 1s
+
Type "man soapdump"
+
Enter
+
Sleep 1s
+
Enter
+
Down 2
+
Sleep 500ms
+
Down 2
+
Sleep 500ms
+
Down 2
+
Sleep 500ms
+
Down 2
+
Sleep 500ms
+
Down 2
+
Sleep 500ms
+
Down 2
+
Sleep 1200ms
+
Type "q"
+
Sleep 500ms
+
Sleep 1s
+
Type "soapdump payments.log"
+
Enter
+
Sleep 3.5s
docs/vhs.gif

This is a binary file and will not be displayed.

+1 -35
flake.lock
···
},
"root": {
"inputs": {
-
"nixpkgs": "nixpkgs",
-
"utils": "utils"
-
}
-
},
-
"systems": {
-
"locked": {
-
"lastModified": 1681028828,
-
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
-
"owner": "nix-systems",
-
"repo": "default",
-
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
-
"type": "github"
-
},
-
"original": {
-
"owner": "nix-systems",
-
"repo": "default",
-
"type": "github"
-
}
-
},
-
"utils": {
-
"inputs": {
-
"systems": "systems"
-
},
-
"locked": {
-
"lastModified": 1731533236,
-
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
-
"owner": "numtide",
-
"repo": "flake-utils",
-
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
-
"type": "github"
-
},
-
"original": {
-
"owner": "numtide",
-
"repo": "flake-utils",
-
"type": "github"
}
}
},
···
},
"root": {
"inputs": {
+
"nixpkgs": "nixpkgs"
}
}
},
+21 -16
flake.nix
···
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
-
outputs = { self, nixpkgs, ... }:
let
allSystems = [
"x86_64-linux" # 64-bit Intel/AMD Linux
···
"x86_64-darwin" # 64-bit Intel macOS
"aarch64-darwin" # 64-bit ARM macOS
];
-
forAllSystems = f:
nixpkgs.lib.genAttrs allSystems (
system:
f {
···
pname = "soapdump";
inherit version;
src = self;
-
-
nativeBuildInputs = with pkgs; [
-
cmake
clang
-
installShellFiles
];
-
buildPhase = ''
-
cmake -B build -S .
-
cmake --build build --config Release
'';
-
installPhase = ''
mkdir -p $out/bin
cp build/soapdump $out/bin/
-
# Generate and install shell completions
mkdir -p completions
$out/bin/soapdump --generate-bash-completion > completions/soapdump.bash
$out/bin/soapdump --generate-zsh-completion > completions/soapdump.zsh
$out/bin/soapdump --generate-fish-completion > completions/soapdump.fish
-
installShellCompletion --cmd soapdump \
--bash completions/soapdump.bash \
--fish completions/soapdump.fish \
--zsh completions/soapdump.zsh
-
# Generate and install man page
mkdir -p $out/share/man/man1
$out/bin/soapdump --man > $out/share/man/man1/soapdump.1
'';
-
meta = with pkgs.lib; {
description = "A high-performance PayPal SOAP log parser";
homepage = "https://github.com/taciturnaxolotl/soapdump";
···
buildInputs = with pkgs; [
cmake
clang
];
-
shellHook = ''
echo "SoapDump development environment loaded"
'';
···
formatter = forAllSystems ({ pkgs }: pkgs.nixfmt-tree);
};
-
}
···
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
+
outputs =
+
{ self, nixpkgs, ... }:
let
allSystems = [
"x86_64-linux" # 64-bit Intel/AMD Linux
···
"x86_64-darwin" # 64-bit Intel macOS
"aarch64-darwin" # 64-bit ARM macOS
];
+
forAllSystems =
+
f:
nixpkgs.lib.genAttrs allSystems (
system:
f {
···
pname = "soapdump";
inherit version;
src = self;
+
+
nativeBuildInputs = with pkgs; [
clang
+
installShellFiles
];
+
+
dontUseCmakeConfigure = true;
+
buildPhase = ''
+
# Direct compilation instead of using CMake
+
mkdir -p build
+
$CXX -std=c++17 -O3 -o build/soapdump $src/src/soapdump.cpp
'';
+
installPhase = ''
mkdir -p $out/bin
cp build/soapdump $out/bin/
+
# Generate and install shell completions
mkdir -p completions
$out/bin/soapdump --generate-bash-completion > completions/soapdump.bash
$out/bin/soapdump --generate-zsh-completion > completions/soapdump.zsh
$out/bin/soapdump --generate-fish-completion > completions/soapdump.fish
+
installShellCompletion --cmd soapdump \
--bash completions/soapdump.bash \
--fish completions/soapdump.fish \
--zsh completions/soapdump.zsh
+
# Generate and install man page
mkdir -p $out/share/man/man1
$out/bin/soapdump --man > $out/share/man/man1/soapdump.1
'';
+
meta = with pkgs.lib; {
description = "A high-performance PayPal SOAP log parser";
homepage = "https://github.com/taciturnaxolotl/soapdump";
···
buildInputs = with pkgs; [
cmake
clang
+
self.packages.${pkgs.system}.default
];
+
shellHook = ''
echo "SoapDump development environment loaded"
'';
···
formatter = forAllSystems ({ pkgs }: pkgs.nixfmt-tree);
};
+
}
+83 -92
src/soapdump.cpp
···
#include <numeric>
#include <iomanip>
#include <getopt.h>
-
#include <unordered_map>
// Transaction data structure
struct Transaction {
···
std::cout << " --generate-zsh-completion Generate Zsh completion script\n";
std::cout << " --generate-fish-completion Generate Fish completion script\n";
std::cout << " --man Generate man page\n\n";
-
std::cout << "OUTPUT FORMAT:\n";
-
std::cout << " TRANS_NUM|AMOUNT|CURRENCY|FIRSTNAME|LASTNAME|STREET|CITY|STATE|ZIP|CCTYPE|CCLAST4|EXPMONTH|EXPYEAR|CVV|TRANSID|STATUS|CORRID|PROC_AMOUNT\n\n";
-
std::cout << "FIELD DESCRIPTIONS:\n";
-
std::cout << " TRANS_NUM - Transaction sequence number\n";
-
std::cout << " AMOUNT - Order total amount\n";
-
std::cout << " CURRENCY - Currency code (USD, etc)\n";
-
std::cout << " FIRSTNAME - Customer first name\n";
-
std::cout << " LASTNAME - Customer last name\n";
-
std::cout << " STREET - Street address\n";
-
std::cout << " CITY - City name\n";
-
std::cout << " STATE - State/Province code\n";
-
std::cout << " ZIP - Postal code\n";
-
std::cout << " CCTYPE - Credit card type (Visa, MasterCard, etc)\n";
-
std::cout << " CCLAST4 - Last 4 digits of credit card\n";
-
std::cout << " EXPMONTH - Card expiration month\n";
-
std::cout << " EXPYEAR - Card expiration year\n";
-
std::cout << " CVV - CVV code\n";
-
std::cout << " TRANSID - PayPal transaction ID\n";
-
std::cout << " STATUS - Transaction status (Success/Failure)\n";
-
std::cout << " CORRID - Correlation ID\n";
-
std::cout << " PROC_AMOUNT - Actually processed amount\n\n";
-
std::cout << "EXAMPLES:\n";
-
std::cout << " # Get all transactions\n";
-
std::cout << " " << programName << " payments.log\n\n";
-
std::cout << " # Get only successful transactions\n";
-
std::cout << " " << programName << " payments.log | grep Success\n\n";
-
std::cout << " # Count transactions by state\n";
-
std::cout << " " << programName << " payments.log | cut -d'|' -f8 | sort | uniq -c | sort -nr\n\n";
-
std::cout << " # Find largest transaction\n";
-
std::cout << " " << programName << " payments.log | sort -t'|' -k2 -nr | head -1\n\n";
-
std::cout << " # Get transactions over $500\n";
-
std::cout << " " << programName << " payments.log | awk -F'|' '$2 > 500'\n\n";
-
std::cout << " # Summary stats\n";
-
std::cout << " " << programName << " -s payments.log\n";
}
void generateBashCompletion() {
···
complete -c soapdump -s h -l help -d "Show help message"
complete -c soapdump -s s -l summary -d "Show summary statistics only"
-
complete -c soapdump -s r -l raw -d "Output raw structured data (default)"
complete -c soapdump -l generate-bash-completion -d "Generate Bash completion script"
complete -c soapdump -l generate-zsh-completion -d "Generate Zsh completion script"
complete -c soapdump -l generate-fish-completion -d "Generate Fish completion script"
···
}
void generateManPage() {
-
std::cout << R"(.TH SOAPDUMP 1 "September 2025" "soapdump 0.1.0" "User Commands"
.SH NAME
-
soapdump \- PayPal SOAP log parser
.SH SYNOPSIS
.B soapdump
-
[\fIOPTIONS\fR] \fILOGFILE\fR
.SH DESCRIPTION
.B soapdump
-
is a high-performance PayPal SOAP log parser that extracts transaction data from log files and outputs it in a structured format.
.SH OPTIONS
.TP
.BR \-h ", " \-\-help
-
Show help message and exit.
.TP
.BR \-s ", " \-\-summary
-
Show summary statistics only.
.TP
.BR \-r ", " \-\-raw
-
Output raw structured data (default).
.TP
.BR \-\-generate-bash-completion
-
Generate Bash completion script.
.TP
.BR \-\-generate-zsh-completion
-
Generate Zsh completion script.
.TP
.BR \-\-generate-fish-completion
-
Generate Fish completion script.
.TP
.BR \-\-man
-
Generate this man page.
.SH OUTPUT FORMAT
-
The output is pipe-separated with the following fields:
-
.PP
TRANS_NUM|AMOUNT|CURRENCY|FIRSTNAME|LASTNAME|STREET|CITY|STATE|ZIP|CCTYPE|CCLAST4|EXPMONTH|EXPYEAR|CVV|TRANSID|STATUS|CORRID|PROC_AMOUNT
.SH EXAMPLES
-
.TP
-
Get all transactions:
-
.B soapdump payments.log
-
.TP
-
Get only successful transactions:
-
.B soapdump payments.log | grep Success
-
.TP
Count transactions by state:
-
.B soapdump payments.log | cut -d'|' -f8 | sort | uniq -c | sort -nr
-
.TP
-
Find largest transaction:
-
.B soapdump payments.log | sort -t'|' -k2 -nr | head -1
-
.TP
-
Get transactions over $500:
-
.B soapdump payments.log | awk -F'|' '$2 > 500'
-
.TP
-
Summary stats:
-
.B soapdump -s payments.log
.SH AUTHOR
-
Kieran Klukas <me@dunkirk.sh>
.SH COPYRIGHT
-
Copyright \(co 2025 Kieran Klukas. License: MIT.
)" << std::endl;
}
···
std::vector<std::string> extractRequests(const std::string& logContent) {
std::vector<std::string> requests;
std::regex pattern("PPAPIService: Request: (.*)");
-
std::string::const_iterator searchStart(logContent.cbegin());
std::smatch match;
while (std::regex_search(searchStart, logContent.cend(), match, pattern)) {
···
}
searchStart = match.suffix().first;
}
-
return requests;
}
std::vector<std::string> extractResponses(const std::string& logContent) {
std::vector<std::string> responses;
std::regex pattern("PPAPIService: Response: <\\?.*\\?>(.*)");
-
std::string::const_iterator searchStart(logContent.cbegin());
std::smatch match;
while (std::regex_search(searchStart, logContent.cend(), match, pattern)) {
···
}
searchStart = match.suffix().first;
}
-
return responses;
}
std::vector<Response> parseResponses(const std::vector<std::string>& responseXmls) {
std::vector<Response> responses;
-
for (const auto& xml : responseXmls) {
Response response;
response.transId = extractXmlValue(xml, "TransactionID");
response.status = extractXmlValue(xml, "Ack");
response.corrId = extractXmlValue(xml, "CorrelationID");
response.procAmount = extractXmlValue(xml, "Amount");
-
responses.push_back(response);
}
-
return responses;
}
std::vector<Transaction> parseTransactions(const std::vector<std::string>& requestXmls, const std::vector<Response>& responses) {
std::vector<Transaction> transactions;
int transNum = 1;
-
for (size_t i = 0; i < requestXmls.size(); ++i) {
const auto& xml = requestXmls[i];
-
Transaction transaction;
transaction.transNum = transNum++;
-
// Extract request fields
transaction.amount = extractXmlValue(xml, "ebl:OrderTotal");
transaction.currency = extractXmlAttribute(xml, "currencyID");
···
transaction.expMonth = extractXmlValue(xml, "ebl:ExpMonth");
transaction.expYear = extractXmlValue(xml, "ebl:ExpYear");
transaction.cvv = extractXmlValue(xml, "ebl:CVV2");
-
// Get corresponding response data
if (i < responses.size()) {
transaction.transId = responses[i].transId;
···
transaction.corrId = responses[i].corrId;
transaction.procAmount = responses[i].procAmount;
}
-
transactions.push_back(transaction);
}
-
return transactions;
}
···
void outputSummary(const std::vector<Transaction>& transactions) {
std::cout << "=== SUMMARY ===" << std::endl;
-
// Count transactions
int total = transactions.size();
-
int successful = std::count_if(transactions.begin(), transactions.end(),
[](const Transaction& t) { return t.status == "Success"; });
-
std::cout << "Total Transactions: " << total << std::endl;
std::cout << "Successful: " << successful << std::endl;
std::cout << "Failed: " << (total - successful) << std::endl;
std::cout << std::endl;
-
// Top 5 states
std::map<std::string, int> stateCounts;
for (const auto& t : transactions) {
stateCounts[t.state]++;
}
-
std::cout << "Top 5 States by Transaction Count:" << std::endl;
std::vector<std::pair<std::string, int>> stateCountVec(stateCounts.begin(), stateCounts.end());
-
std::sort(stateCountVec.begin(), stateCountVec.end(),
[](const auto& a, const auto& b) { return a.second > b.second; });
-
int count = 0;
for (const auto& sc : stateCountVec) {
if (count++ >= 5) break;
std::cout << " " << sc.first << ": " << sc.second << std::endl;
}
std::cout << std::endl;
-
// Transaction amount stats
std::vector<double> amounts;
for (const auto& t : transactions) {
···
// Skip invalid amounts
}
}
-
if (!amounts.empty()) {
double totalAmount = std::accumulate(amounts.begin(), amounts.end(), 0.0);
double largest = *std::max_element(amounts.begin(), amounts.end());
double smallest = *std::min_element(amounts.begin(), amounts.end());
-
std::cout << "Transaction Amount Stats:" << std::endl;
std::cout << " Total: $" << std::fixed << std::setprecision(2) << totalAmount << std::endl;
std::cout << " Largest: $" << std::fixed << std::setprecision(2) << largest << std::endl;
std::cout << " Smallest: $" << std::fixed << std::setprecision(2) << smallest << std::endl;
}
-
}
···
#include <numeric>
#include <iomanip>
#include <getopt.h>
+
#include <cstring>
// Transaction data structure
struct Transaction {
···
std::cout << " --generate-zsh-completion Generate Zsh completion script\n";
std::cout << " --generate-fish-completion Generate Fish completion script\n";
std::cout << " --man Generate man page\n\n";
+
std::cout << "For detailed information, field descriptions, and examples, run:\n";
+
std::cout << " man " << programName << " \n";
}
void generateBashCompletion() {
···
complete -c soapdump -s h -l help -d "Show help message"
complete -c soapdump -s s -l summary -d "Show summary statistics only"
+
complete -c soapdump -s r -l raw -d "Output raw structured data"
complete -c soapdump -l generate-bash-completion -d "Generate Bash completion script"
complete -c soapdump -l generate-zsh-completion -d "Generate Zsh completion script"
complete -c soapdump -l generate-fish-completion -d "Generate Fish completion script"
···
}
void generateManPage() {
+
std::cout << R"(.TH SOAPDUMP 1 "December 2024" "soapdump 1.0" "User Commands"
.SH NAME
+
soapdump \- parse PayPal SOAP transaction logs
.SH SYNOPSIS
.B soapdump
+
[\fIOPTIONS\fR] \fIlogfile\fR
.SH DESCRIPTION
.B soapdump
+
parses PayPal SOAP log files to extract transaction data. It reads log entries containing XML request/response pairs and outputs structured transaction information in pipe-delimited format suitable for further processing with standard Unix tools.
+
+
The program matches SOAP requests with their corresponding responses to provide complete transaction records including customer information, payment details, and processing results.
.SH OPTIONS
.TP
.BR \-h ", " \-\-help
+
Display help information and exit
.TP
.BR \-s ", " \-\-summary
+
Display summary statistics instead of raw transaction data
.TP
.BR \-r ", " \-\-raw
+
Output raw transaction data in pipe-delimited format (default behavior)
.TP
.BR \-\-generate-bash-completion
+
Output bash shell completion script
.TP
.BR \-\-generate-zsh-completion
+
Output zsh shell completion script
.TP
.BR \-\-generate-fish-completion
+
Output fish shell completion script
.TP
.BR \-\-man
+
Output this manual page in troff format
.SH OUTPUT FORMAT
+
By default, transactions are output one per line with pipe-separated fields:
+
TRANS_NUM|AMOUNT|CURRENCY|FIRSTNAME|LASTNAME|STREET|CITY|STATE|ZIP|CCTYPE|CCLAST4|EXPMONTH|EXPYEAR|CVV|TRANSID|STATUS|CORRID|PROC_AMOUNT
+
+
Fields may be empty if not present in the source data.
.SH EXAMPLES
+
Parse a log file and display all transactions:
+
.RS
+
.B soapdump paypal.log
+
.RE
+
+
Show only successful transactions:
+
.RS
+
.B soapdump paypal.log | grep '|Success|'
+
.RE
+
Count transactions by state:
+
.RS
+
.B soapdump paypal.log | cut -d'|' -f8 | sort | uniq -c | sort -rn
+
.RE
+
+
Find the largest transaction amount:
+
.RS
+
.B soapdump paypal.log | sort -t'|' -k2 -rn | head -1
+
.RE
+
+
Show transactions over $500:
+
.RS
+
.B soapdump paypal.log | awk -F'|' '$2 > 500'
+
.RE
+
+
Display summary statistics:
+
.RS
+
.B soapdump --summary paypal.log
+
.RE
+
.SH FILES
+
The input file should contain PayPal SOAP API log entries with request and response XML data.
.SH AUTHOR
+
Written by Kieran Klukas.
+
.SH REPORTING BUGS
+
Report bugs to <me@dunkirk.sh>
.SH COPYRIGHT
+
Copyright \(co 2024 Kieran Klukas.
+
License MIT: <https://opensource.org/licenses/MIT>
+
.br
+
This is free software: you are free to change and redistribute it.
+
There is NO WARRANTY, to the extent permitted by law.
)" << std::endl;
}
···
std::vector<std::string> extractRequests(const std::string& logContent) {
std::vector<std::string> requests;
std::regex pattern("PPAPIService: Request: (.*)");
+
std::string::const_iterator searchStart(logContent.cbegin());
std::smatch match;
while (std::regex_search(searchStart, logContent.cend(), match, pattern)) {
···
}
searchStart = match.suffix().first;
}
+
return requests;
}
std::vector<std::string> extractResponses(const std::string& logContent) {
std::vector<std::string> responses;
std::regex pattern("PPAPIService: Response: <\\?.*\\?>(.*)");
+
std::string::const_iterator searchStart(logContent.cbegin());
std::smatch match;
while (std::regex_search(searchStart, logContent.cend(), match, pattern)) {
···
}
searchStart = match.suffix().first;
}
+
return responses;
}
std::vector<Response> parseResponses(const std::vector<std::string>& responseXmls) {
std::vector<Response> responses;
+
for (const auto& xml : responseXmls) {
Response response;
response.transId = extractXmlValue(xml, "TransactionID");
response.status = extractXmlValue(xml, "Ack");
response.corrId = extractXmlValue(xml, "CorrelationID");
response.procAmount = extractXmlValue(xml, "Amount");
+
responses.push_back(response);
}
+
return responses;
}
std::vector<Transaction> parseTransactions(const std::vector<std::string>& requestXmls, const std::vector<Response>& responses) {
std::vector<Transaction> transactions;
int transNum = 1;
+
for (size_t i = 0; i < requestXmls.size(); ++i) {
const auto& xml = requestXmls[i];
+
Transaction transaction;
transaction.transNum = transNum++;
+
// Extract request fields
transaction.amount = extractXmlValue(xml, "ebl:OrderTotal");
transaction.currency = extractXmlAttribute(xml, "currencyID");
···
transaction.expMonth = extractXmlValue(xml, "ebl:ExpMonth");
transaction.expYear = extractXmlValue(xml, "ebl:ExpYear");
transaction.cvv = extractXmlValue(xml, "ebl:CVV2");
+
// Get corresponding response data
if (i < responses.size()) {
transaction.transId = responses[i].transId;
···
transaction.corrId = responses[i].corrId;
transaction.procAmount = responses[i].procAmount;
}
+
transactions.push_back(transaction);
}
+
return transactions;
}
···
void outputSummary(const std::vector<Transaction>& transactions) {
std::cout << "=== SUMMARY ===" << std::endl;
+
// Count transactions
int total = transactions.size();
+
int successful = std::count_if(transactions.begin(), transactions.end(),
[](const Transaction& t) { return t.status == "Success"; });
+
std::cout << "Total Transactions: " << total << std::endl;
std::cout << "Successful: " << successful << std::endl;
std::cout << "Failed: " << (total - successful) << std::endl;
std::cout << std::endl;
+
// Top 5 states
std::map<std::string, int> stateCounts;
for (const auto& t : transactions) {
stateCounts[t.state]++;
}
+
std::cout << "Top 5 States by Transaction Count:" << std::endl;
std::vector<std::pair<std::string, int>> stateCountVec(stateCounts.begin(), stateCounts.end());
+
std::sort(stateCountVec.begin(), stateCountVec.end(),
[](const auto& a, const auto& b) { return a.second > b.second; });
+
int count = 0;
for (const auto& sc : stateCountVec) {
if (count++ >= 5) break;
std::cout << " " << sc.first << ": " << sc.second << std::endl;
}
std::cout << std::endl;
+
// Transaction amount stats
std::vector<double> amounts;
for (const auto& t : transactions) {
···
// Skip invalid amounts
}
}
+
if (!amounts.empty()) {
double totalAmount = std::accumulate(amounts.begin(), amounts.end(), 0.0);
double largest = *std::max_element(amounts.begin(), amounts.end());
double smallest = *std::min_element(amounts.begin(), amounts.end());
+
std::cout << "Transaction Amount Stats:" << std::endl;
std::cout << " Total: $" << std::fixed << std::setprecision(2) << totalAmount << std::endl;
std::cout << " Largest: $" << std::fixed << std::setprecision(2) << largest << std::endl;
std::cout << " Smallest: $" << std::fixed << std::setprecision(2) << smallest << std::endl;
}
+
}