strapi-plugin-payone-provider 1.6.6 → 1.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -145,15 +145,25 @@ const addPaymentMethodParams = (params, logger) => {
145
145
  try {
146
146
  const tokenString = Buffer.from(updated.applePayToken, 'base64').toString('utf-8');
147
147
  tokenData = JSON.parse(tokenString);
148
+
149
+ if (logger) {
150
+ logger.info("[Apple Pay] Token decoded from Base64 successfully");
151
+ }
148
152
  } catch (e) {
149
153
  try {
150
- // Try parsing as JSON string directly
151
154
  tokenData = typeof updated.applePayToken === 'string'
152
155
  ? JSON.parse(updated.applePayToken)
153
156
  : updated.applePayToken;
157
+
158
+ if (logger) {
159
+ logger.info("[Apple Pay] Token parsed as JSON string directly");
160
+ }
154
161
  } catch (e2) {
155
- // If already an object, use as-is
156
162
  tokenData = updated.applePayToken;
163
+
164
+ if (logger) {
165
+ logger.info("[Apple Pay] Token used as-is (already an object)");
166
+ }
157
167
  }
158
168
  }
159
169
 
@@ -162,7 +172,10 @@ const addPaymentMethodParams = (params, logger) => {
162
172
 
163
173
  if (!paymentData) {
164
174
  if (logger) {
165
- logger.error("[Apple Pay] Invalid token structure: missing paymentData field");
175
+ logger.error("[Apple Pay] Invalid token structure: missing paymentData field", {
176
+ tokenKeys: Object.keys(tokenData),
177
+ tokenStructure: JSON.stringify(tokenData).substring(0, 500)
178
+ });
166
179
  }
167
180
  delete updated.applePayToken;
168
181
  return updated;
@@ -171,30 +184,66 @@ const addPaymentMethodParams = (params, logger) => {
171
184
  const header = paymentData.header || {};
172
185
 
173
186
  // Payone required fields according to docs
174
- updated["add_paydata[paymentdata_token_version]"] = paymentData.version || "EC_v1";
175
- updated["add_paydata[paymentdata_token_data]"] = paymentData.data || "";
176
- updated["add_paydata[paymentdata_token_signature]"] = paymentData.signature || "";
177
- updated["add_paydata[paymentdata_token_ephemeral_publickey]"] = header.ephemeralPublicKey || "";
178
- updated["add_paydata[paymentdata_token_publickey_hash]"] = header.publicKeyHash || "";
187
+ // Extract version, data, signature from paymentData
188
+ const tokenVersion = paymentData.version || "EC_v1";
189
+ const tokenDataValue = paymentData.data || "";
190
+ const tokenSignature = paymentData.signature || "";
191
+
192
+ // Extract from header
193
+ const ephemeralPublicKey = header.ephemeralPublicKey || "";
194
+ const publicKeyHash = header.publicKeyHash || "";
195
+ const transactionId = paymentData.transactionId || header.transactionId || "";
196
+
197
+ // Set Payone required fields
198
+ updated["add_paydata[paymentdata_token_version]"] = tokenVersion;
199
+ updated["add_paydata[paymentdata_token_data]"] = tokenDataValue;
200
+ updated["add_paydata[paymentdata_token_signature]"] = tokenSignature;
201
+ updated["add_paydata[paymentdata_token_ephemeral_publickey]"] = ephemeralPublicKey;
202
+ updated["add_paydata[paymentdata_token_publickey_hash]"] = publicKeyHash;
179
203
 
180
204
  // Transaction ID is optional according to Payone docs
181
- if (paymentData.transactionId || header.transactionId) {
182
- updated["add_paydata[paymentdata_token_transaction_id]"] = paymentData.transactionId || header.transactionId || "";
205
+ if (transactionId) {
206
+ updated["add_paydata[paymentdata_token_transaction_id]"] = transactionId;
207
+ }
208
+
209
+ if (logger) {
210
+ logger.info("[Apple Pay] Token extracted successfully:", {
211
+ hasVersion: !!tokenVersion,
212
+ hasData: !!tokenDataValue,
213
+ hasSignature: !!tokenSignature,
214
+ hasEphemeralPublicKey: !!ephemeralPublicKey,
215
+ hasPublicKeyHash: !!publicKeyHash,
216
+ hasTransactionId: !!transactionId,
217
+ dataLength: tokenDataValue.length,
218
+ signatureLength: tokenSignature.length,
219
+ ephemeralPublicKeyLength: ephemeralPublicKey.length,
220
+ publicKeyHashLength: publicKeyHash.length
221
+ });
183
222
  }
184
223
 
185
- if (!updated["add_paydata[paymentdata_token_data]"] ||
186
- !updated["add_paydata[paymentdata_token_signature]"] ||
187
- !updated["add_paydata[paymentdata_token_ephemeral_publickey]"] ||
188
- !updated["add_paydata[paymentdata_token_publickey_hash]"]) {
224
+ // Validate required fields
225
+ if (!tokenDataValue ||
226
+ !tokenSignature ||
227
+ !ephemeralPublicKey ||
228
+ !publicKeyHash) {
189
229
  if (logger) {
190
230
  logger.error("[Apple Pay] Missing required token fields:", {
191
- hasData: !!updated["add_paydata[paymentdata_token_data]"],
192
- hasSignature: !!updated["add_paydata[paymentdata_token_signature]"],
193
- hasEphemeralPublicKey: !!updated["add_paydata[paymentdata_token_ephemeral_publickey]"],
194
- hasPublicKeyHash: !!updated["add_paydata[paymentdata_token_publickey_hash]"]
231
+ hasData: !!tokenDataValue,
232
+ hasSignature: !!tokenSignature,
233
+ hasEphemeralPublicKey: !!ephemeralPublicKey,
234
+ hasPublicKeyHash: !!publicKeyHash,
235
+ paymentDataKeys: Object.keys(paymentData),
236
+ headerKeys: Object.keys(header)
195
237
  });
196
238
  }
197
239
  }
240
+ } else {
241
+ if (logger) {
242
+ logger.error("[Apple Pay] Token is not a valid object:", {
243
+ tokenType: typeof tokenData,
244
+ tokenValue: typeof tokenData === 'string' ? tokenData.substring(0, 200) : String(tokenData).substring(0, 200)
245
+ });
246
+ }
198
247
  }
199
248
 
200
249
  delete updated.applePayToken;