-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_calls.sh
More file actions
147 lines (135 loc) · 6.01 KB
/
Copy pathapi_calls.sh
File metadata and controls
147 lines (135 loc) · 6.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
# =============================================================================
# Token Rotation - Raw API Calls
# =============================================================================
# Generated by Web API MCP Server during development session
# Date: 2025-12-13
#
# This script shows the exact API calls needed for token rotation.
# It's generated from actual successful API calls made during development.
#
# USAGE:
# export WEB_API_CREDENTIALS='username:password'
# bash api_calls.sh
#
# NOTE: This is for reference/testing. Use token_rotation.py for production.
# =============================================================================
set -e # Exit on error
# Configuration - Replace these with your values
MERCHANT_ID="MERCHANT_ID"
CHANNEL_ID="CHANNEL_ID"
BASE_URL="https://domain.com/api/v1"
AUTH_FAILED_ERROR_CODE="nnn.nnn.nnn"
# Check credentials
if [ -z "$WEB_API_CREDENTIALS" ]; then
echo "ERROR: Set WEB_API_CREDENTIALS environment variable"
echo " export WEB_API_CREDENTIALS='username:password'"
exit 1
fi
echo "=== Token Rotation API Calls ==="
echo ""
# -----------------------------------------------------------------------------
# STEP 1: Get current Channel state (capture current token)
# -----------------------------------------------------------------------------
echo "STEP 1: Query Channel for current token"
echo "------------------------------------------------------------------------"
curl -s -X GET \
"${BASE_URL}/channels/${CHANNEL_ID}" \
-H "credentials: $WEB_API_CREDENTIALS" \
-H "Accept: application/json" | jq .
echo ""
# -----------------------------------------------------------------------------
# STEP 2: List currently attached Contacts at Merchant level
# -----------------------------------------------------------------------------
echo "STEP 2: List attached Contacts at Merchant level"
echo "------------------------------------------------------------------------"
curl -s -X GET \
"${BASE_URL}/merchants/${MERCHANT_ID}/attachedContacts" \
-H "credentials: $WEB_API_CREDENTIALS" \
-H "Accept: application/json" | jq .
echo ""
# -----------------------------------------------------------------------------
# STEP 3: Create new SYSTEM Contact with autoAttach=true
# -----------------------------------------------------------------------------
echo "STEP 3: Create new SYSTEM Contact"
echo "------------------------------------------------------------------------"
# Generate email/name based on date
DATE_SUFFIX=$(date +%Y%m%d)
CONTACT_EMAIL="mercha${DATE_SUFFIX}@domain.com"
CONTACT_NAME="mercha${DATE_SUFFIX}"
curl -s -X POST \
"${BASE_URL}/merchants/${MERCHANT_ID}/ownedContacts" \
-H "credentials: $WEB_API_CREDENTIALS" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json" \
-d "email=${CONTACT_EMAIL}" \
-d "name=${CONTACT_NAME}" \
-d "role=OPERATOR" \
-d "kind=SYSTEM" \
-d "language=en" \
-d "autoAttach=true" | jq .
echo ""
# -----------------------------------------------------------------------------
# STEP 4: Detach old SYSTEM Contact - CAUSES PROCESSING INTERRUPTION! (ms)
# -----------------------------------------------------------------------------
echo "STEP 4: Detach old SYSTEM Contact"
echo "------------------------------------------------------------------------"
echo "NOTE: Replace OLD_CONTACT_ID with the ID of the current SYSTEM contact"
echo " from Step 2 output. Processing will be interrupted until Step 5."
echo ""
# Example: OLD_CONTACT_ID="8ac7a4c89b12fcc7019b18e282660274"
# curl -s -X DELETE \
# "${BASE_URL}/merchants/${MERCHANT_ID}/attachedContacts/${OLD_CONTACT_ID}" \
# -H "credentials: $WEB_API_CREDENTIALS" \
# -H "Accept: application/json" | jq .
echo "(Commented out - requires manual OLD_CONTACT_ID)"
echo ""
# -----------------------------------------------------------------------------
# STEP 5: Query Channel to get NEW token
# -----------------------------------------------------------------------------
echo "STEP 5: Query Channel for NEW token (after detach)"
echo "------------------------------------------------------------------------"
echo "This will return the accessToken for the newly created Contact"
curl -s -X GET \
"${BASE_URL}/channels/${CHANNEL_ID}" \
-H "credentials: $WEB_API_CREDENTIALS" \
-H "Accept: application/json" | jq .
echo ""
# -----------------------------------------------------------------------------
# STEP 6: Re-attach non-SYSTEM Contacts (if any were detached)
# -----------------------------------------------------------------------------
echo "STEP 6: Re-attach non-SYSTEM Contacts"
echo "------------------------------------------------------------------------"
echo "NOTE: For each non-SYSTEM contact that was detached in Step 4:"
# Example: NON_SYSTEM_CONTACT_ID="..."
# curl -s -X POST \
# "${BASE_URL}/merchants/${MERCHANT_ID}/attachedContacts/${NON_SYSTEM_CONTACT_ID}" \
# -H "credentials: $WEB_API_CREDENTIALS" \
# -H "Accept: application/json" | jq .
echo "(Only needed if non-SYSTEM contacts existed)"
echo ""
# -----------------------------------------------------------------------------
# STEP 7: Verify with test transaction
# -----------------------------------------------------------------------------
echo "STEP 7: Test transaction with NEW token"
echo "------------------------------------------------------------------------"
echo "Replace NEW_ACCESS_TOKEN with the accessToken from Step 5"
echo ""
# NEW_ACCESS_TOKEN="OGFjN2E0..."
# curl -s https://domain.com/v1/payments \
# -d "entityId=${CHANNEL_ID}" \
# -d "amount=92.00" \
# -d "currency=EUR" \
# -d "paymentBrand=VISA" \
# -d "paymentType=DB" \
# -d "card.number=420000******0000" \
# -d "card.holder=Card Holder" \
# -d "card.expiryMonth=11" \
# -d "card.expiryYear=2033" \
# -d "card.cvv=111" \
# -d "merchantTransactionId=test-$(date +%s)" \
# -H "Authorization: Bearer ${NEW_ACCESS_TOKEN}" | jq .
echo "(Commented out - requires NEW_ACCESS_TOKEN)"
echo ""
echo "SUCCESS if result.code != ${AUTH_FAILED_ERROR_CODE}"
echo "=== End of Token Rotation API Calls ==="