@paykit-sdk/medusajs 1.0.10 → 1.0.11
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.
package/dist/index.js
CHANGED
|
@@ -368,6 +368,108 @@ var PaykitMedusaJSAdapter = class extends utils.AbstractPaymentProvider {
|
|
|
368
368
|
});
|
|
369
369
|
return webhookEvents;
|
|
370
370
|
};
|
|
371
|
+
createAccountHolder = async ({
|
|
372
|
+
context,
|
|
373
|
+
data
|
|
374
|
+
}) => {
|
|
375
|
+
if (this.options.debug) {
|
|
376
|
+
console.info("[PayKit] Creating account holder", context, data);
|
|
377
|
+
}
|
|
378
|
+
const { customer, account_holder } = context;
|
|
379
|
+
if (account_holder?.data?.id) {
|
|
380
|
+
return { id: account_holder.data.id };
|
|
381
|
+
}
|
|
382
|
+
if (!customer) {
|
|
383
|
+
throw new utils.MedusaError(
|
|
384
|
+
utils.MedusaError.Types.INVALID_DATA,
|
|
385
|
+
"Customer not found in context"
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
const [accountHolderResult, accountHolderError] = await core.tryCatchAsync(
|
|
389
|
+
this.paykit.customers.create({
|
|
390
|
+
email: customer.email,
|
|
391
|
+
name: customer.email.split("@")[0],
|
|
392
|
+
phone: customer.phone,
|
|
393
|
+
metadata: {
|
|
394
|
+
PAYKIT_METADATA_KEY: JSON.stringify({ source: "medusa-paykit-adapter" })
|
|
395
|
+
}
|
|
396
|
+
})
|
|
397
|
+
);
|
|
398
|
+
if (accountHolderError) {
|
|
399
|
+
throw new utils.MedusaError(
|
|
400
|
+
utils.MedusaError.Types.PAYMENT_AUTHORIZATION_ERROR,
|
|
401
|
+
accountHolderError.message
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
return {
|
|
405
|
+
id: accountHolderResult.id,
|
|
406
|
+
data: accountHolderResult
|
|
407
|
+
};
|
|
408
|
+
};
|
|
409
|
+
updateAccountHolder = async ({
|
|
410
|
+
context,
|
|
411
|
+
data
|
|
412
|
+
}) => {
|
|
413
|
+
if (this.options.debug) {
|
|
414
|
+
console.info("[PayKit] Updating account holder", context, data);
|
|
415
|
+
}
|
|
416
|
+
const { account_holder, customer, idempotency_key } = context;
|
|
417
|
+
if (!account_holder.data?.id) {
|
|
418
|
+
throw new utils.MedusaError(
|
|
419
|
+
utils.MedusaError.Types.INVALID_DATA,
|
|
420
|
+
"Account holder not found in context"
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
if (!customer) {
|
|
424
|
+
return {};
|
|
425
|
+
}
|
|
426
|
+
const accountHolderId = account_holder.data.id;
|
|
427
|
+
const [accountHolderResult, accountHolderError] = await core.tryCatchAsync(
|
|
428
|
+
this.paykit.customers.update(accountHolderId, {
|
|
429
|
+
email: customer.email,
|
|
430
|
+
name: customer.email.split("@")[0],
|
|
431
|
+
phone: customer.phone,
|
|
432
|
+
...data?.metadata && {
|
|
433
|
+
metadata: core.stringifyMetadataValues(
|
|
434
|
+
data?.metadata ?? {}
|
|
435
|
+
)
|
|
436
|
+
}
|
|
437
|
+
})
|
|
438
|
+
);
|
|
439
|
+
if (accountHolderError) {
|
|
440
|
+
throw new utils.MedusaError(
|
|
441
|
+
utils.MedusaError.Types.PAYMENT_AUTHORIZATION_ERROR,
|
|
442
|
+
accountHolderError.message
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
return { data: accountHolderResult };
|
|
446
|
+
};
|
|
447
|
+
deleteAccountHolder = async ({
|
|
448
|
+
context,
|
|
449
|
+
data
|
|
450
|
+
}) => {
|
|
451
|
+
if (this.options.debug) {
|
|
452
|
+
console.info("[PayKit] Deleting account holder", context, data);
|
|
453
|
+
}
|
|
454
|
+
const { account_holder } = context;
|
|
455
|
+
if (!account_holder.data?.id) {
|
|
456
|
+
throw new utils.MedusaError(
|
|
457
|
+
utils.MedusaError.Types.INVALID_DATA,
|
|
458
|
+
"Account holder not found in context"
|
|
459
|
+
);
|
|
460
|
+
}
|
|
461
|
+
const accountHolderId = account_holder.data.id;
|
|
462
|
+
const [accountHolderResult, accountHolderError] = await core.tryCatchAsync(
|
|
463
|
+
this.paykit.customers.delete(accountHolderId)
|
|
464
|
+
);
|
|
465
|
+
if (accountHolderError) {
|
|
466
|
+
throw new utils.MedusaError(
|
|
467
|
+
utils.MedusaError.Types.PAYMENT_AUTHORIZATION_ERROR,
|
|
468
|
+
accountHolderError.message
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
return { data: accountHolderResult };
|
|
472
|
+
};
|
|
371
473
|
};
|
|
372
474
|
|
|
373
475
|
// src/index.ts
|
package/dist/index.mjs
CHANGED
|
@@ -364,6 +364,108 @@ var PaykitMedusaJSAdapter = class extends AbstractPaymentProvider {
|
|
|
364
364
|
});
|
|
365
365
|
return webhookEvents;
|
|
366
366
|
};
|
|
367
|
+
createAccountHolder = async ({
|
|
368
|
+
context,
|
|
369
|
+
data
|
|
370
|
+
}) => {
|
|
371
|
+
if (this.options.debug) {
|
|
372
|
+
console.info("[PayKit] Creating account holder", context, data);
|
|
373
|
+
}
|
|
374
|
+
const { customer, account_holder } = context;
|
|
375
|
+
if (account_holder?.data?.id) {
|
|
376
|
+
return { id: account_holder.data.id };
|
|
377
|
+
}
|
|
378
|
+
if (!customer) {
|
|
379
|
+
throw new MedusaError(
|
|
380
|
+
MedusaError.Types.INVALID_DATA,
|
|
381
|
+
"Customer not found in context"
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
const [accountHolderResult, accountHolderError] = await tryCatchAsync(
|
|
385
|
+
this.paykit.customers.create({
|
|
386
|
+
email: customer.email,
|
|
387
|
+
name: customer.email.split("@")[0],
|
|
388
|
+
phone: customer.phone,
|
|
389
|
+
metadata: {
|
|
390
|
+
PAYKIT_METADATA_KEY: JSON.stringify({ source: "medusa-paykit-adapter" })
|
|
391
|
+
}
|
|
392
|
+
})
|
|
393
|
+
);
|
|
394
|
+
if (accountHolderError) {
|
|
395
|
+
throw new MedusaError(
|
|
396
|
+
MedusaError.Types.PAYMENT_AUTHORIZATION_ERROR,
|
|
397
|
+
accountHolderError.message
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
return {
|
|
401
|
+
id: accountHolderResult.id,
|
|
402
|
+
data: accountHolderResult
|
|
403
|
+
};
|
|
404
|
+
};
|
|
405
|
+
updateAccountHolder = async ({
|
|
406
|
+
context,
|
|
407
|
+
data
|
|
408
|
+
}) => {
|
|
409
|
+
if (this.options.debug) {
|
|
410
|
+
console.info("[PayKit] Updating account holder", context, data);
|
|
411
|
+
}
|
|
412
|
+
const { account_holder, customer, idempotency_key } = context;
|
|
413
|
+
if (!account_holder.data?.id) {
|
|
414
|
+
throw new MedusaError(
|
|
415
|
+
MedusaError.Types.INVALID_DATA,
|
|
416
|
+
"Account holder not found in context"
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
if (!customer) {
|
|
420
|
+
return {};
|
|
421
|
+
}
|
|
422
|
+
const accountHolderId = account_holder.data.id;
|
|
423
|
+
const [accountHolderResult, accountHolderError] = await tryCatchAsync(
|
|
424
|
+
this.paykit.customers.update(accountHolderId, {
|
|
425
|
+
email: customer.email,
|
|
426
|
+
name: customer.email.split("@")[0],
|
|
427
|
+
phone: customer.phone,
|
|
428
|
+
...data?.metadata && {
|
|
429
|
+
metadata: stringifyMetadataValues(
|
|
430
|
+
data?.metadata ?? {}
|
|
431
|
+
)
|
|
432
|
+
}
|
|
433
|
+
})
|
|
434
|
+
);
|
|
435
|
+
if (accountHolderError) {
|
|
436
|
+
throw new MedusaError(
|
|
437
|
+
MedusaError.Types.PAYMENT_AUTHORIZATION_ERROR,
|
|
438
|
+
accountHolderError.message
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
return { data: accountHolderResult };
|
|
442
|
+
};
|
|
443
|
+
deleteAccountHolder = async ({
|
|
444
|
+
context,
|
|
445
|
+
data
|
|
446
|
+
}) => {
|
|
447
|
+
if (this.options.debug) {
|
|
448
|
+
console.info("[PayKit] Deleting account holder", context, data);
|
|
449
|
+
}
|
|
450
|
+
const { account_holder } = context;
|
|
451
|
+
if (!account_holder.data?.id) {
|
|
452
|
+
throw new MedusaError(
|
|
453
|
+
MedusaError.Types.INVALID_DATA,
|
|
454
|
+
"Account holder not found in context"
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
const accountHolderId = account_holder.data.id;
|
|
458
|
+
const [accountHolderResult, accountHolderError] = await tryCatchAsync(
|
|
459
|
+
this.paykit.customers.delete(accountHolderId)
|
|
460
|
+
);
|
|
461
|
+
if (accountHolderError) {
|
|
462
|
+
throw new MedusaError(
|
|
463
|
+
MedusaError.Types.PAYMENT_AUTHORIZATION_ERROR,
|
|
464
|
+
accountHolderError.message
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
return { data: accountHolderResult };
|
|
468
|
+
};
|
|
367
469
|
};
|
|
368
470
|
|
|
369
471
|
// src/index.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InitiatePaymentInput, InitiatePaymentOutput, CapturePaymentInput, CapturePaymentOutput, AuthorizePaymentInput, AuthorizePaymentOutput, CancelPaymentInput, CancelPaymentOutput, DeletePaymentInput, DeletePaymentOutput, GetPaymentStatusInput, GetPaymentStatusOutput, RefundPaymentInput, RefundPaymentOutput, RetrievePaymentInput, RetrievePaymentOutput, UpdatePaymentInput, UpdatePaymentOutput, ProviderWebhookPayload, WebhookActionResult } from '@medusajs/framework/types';
|
|
1
|
+
import { InitiatePaymentInput, InitiatePaymentOutput, CapturePaymentInput, CapturePaymentOutput, AuthorizePaymentInput, AuthorizePaymentOutput, CancelPaymentInput, CancelPaymentOutput, DeletePaymentInput, DeletePaymentOutput, GetPaymentStatusInput, GetPaymentStatusOutput, RefundPaymentInput, RefundPaymentOutput, RetrievePaymentInput, RetrievePaymentOutput, UpdatePaymentInput, UpdatePaymentOutput, ProviderWebhookPayload, WebhookActionResult, CreateAccountHolderInput, CreateAccountHolderOutput, UpdateAccountHolderInput, UpdateAccountHolderOutput, DeleteAccountHolderInput, DeleteAccountHolderOutput } from '@medusajs/framework/types';
|
|
2
2
|
import { AbstractPaymentProvider } from '@medusajs/framework/utils';
|
|
3
3
|
import { PayKitProvider, PayKit } from '@paykit-sdk/core';
|
|
4
4
|
import { z } from 'zod';
|
|
@@ -56,6 +56,9 @@ declare class PaykitMedusaJSAdapter extends AbstractPaymentProvider<PaykitMedusa
|
|
|
56
56
|
retrievePayment: (input: RetrievePaymentInput) => Promise<RetrievePaymentOutput>;
|
|
57
57
|
updatePayment: (input: UpdatePaymentInput) => Promise<UpdatePaymentOutput>;
|
|
58
58
|
getWebhookActionAndData: (payload: ProviderWebhookPayload["payload"]) => Promise<WebhookActionResult>;
|
|
59
|
+
createAccountHolder: ({ context, data, }: CreateAccountHolderInput) => Promise<CreateAccountHolderOutput>;
|
|
60
|
+
updateAccountHolder: ({ context, data, }: UpdateAccountHolderInput) => Promise<UpdateAccountHolderOutput>;
|
|
61
|
+
deleteAccountHolder: ({ context, data, }: DeleteAccountHolderInput) => Promise<DeleteAccountHolderOutput>;
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
export { PaykitMedusaJSAdapter, type PaykitMedusaJSAdapterOptions };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InitiatePaymentInput, InitiatePaymentOutput, CapturePaymentInput, CapturePaymentOutput, AuthorizePaymentInput, AuthorizePaymentOutput, CancelPaymentInput, CancelPaymentOutput, DeletePaymentInput, DeletePaymentOutput, GetPaymentStatusInput, GetPaymentStatusOutput, RefundPaymentInput, RefundPaymentOutput, RetrievePaymentInput, RetrievePaymentOutput, UpdatePaymentInput, UpdatePaymentOutput, ProviderWebhookPayload, WebhookActionResult } from '@medusajs/framework/types';
|
|
1
|
+
import { InitiatePaymentInput, InitiatePaymentOutput, CapturePaymentInput, CapturePaymentOutput, AuthorizePaymentInput, AuthorizePaymentOutput, CancelPaymentInput, CancelPaymentOutput, DeletePaymentInput, DeletePaymentOutput, GetPaymentStatusInput, GetPaymentStatusOutput, RefundPaymentInput, RefundPaymentOutput, RetrievePaymentInput, RetrievePaymentOutput, UpdatePaymentInput, UpdatePaymentOutput, ProviderWebhookPayload, WebhookActionResult, CreateAccountHolderInput, CreateAccountHolderOutput, UpdateAccountHolderInput, UpdateAccountHolderOutput, DeleteAccountHolderInput, DeleteAccountHolderOutput } from '@medusajs/framework/types';
|
|
2
2
|
import { AbstractPaymentProvider } from '@medusajs/framework/utils';
|
|
3
3
|
import { PayKitProvider, PayKit } from '@paykit-sdk/core';
|
|
4
4
|
import { z } from 'zod';
|
|
@@ -56,6 +56,9 @@ declare class PaykitMedusaJSAdapter extends AbstractPaymentProvider<PaykitMedusa
|
|
|
56
56
|
retrievePayment: (input: RetrievePaymentInput) => Promise<RetrievePaymentOutput>;
|
|
57
57
|
updatePayment: (input: UpdatePaymentInput) => Promise<UpdatePaymentOutput>;
|
|
58
58
|
getWebhookActionAndData: (payload: ProviderWebhookPayload["payload"]) => Promise<WebhookActionResult>;
|
|
59
|
+
createAccountHolder: ({ context, data, }: CreateAccountHolderInput) => Promise<CreateAccountHolderOutput>;
|
|
60
|
+
updateAccountHolder: ({ context, data, }: UpdateAccountHolderInput) => Promise<UpdateAccountHolderOutput>;
|
|
61
|
+
deleteAccountHolder: ({ context, data, }: DeleteAccountHolderInput) => Promise<DeleteAccountHolderOutput>;
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
export { PaykitMedusaJSAdapter, type PaykitMedusaJSAdapterOptions };
|
|
@@ -366,6 +366,108 @@ var PaykitMedusaJSAdapter = class extends utils.AbstractPaymentProvider {
|
|
|
366
366
|
});
|
|
367
367
|
return webhookEvents;
|
|
368
368
|
};
|
|
369
|
+
createAccountHolder = async ({
|
|
370
|
+
context,
|
|
371
|
+
data
|
|
372
|
+
}) => {
|
|
373
|
+
if (this.options.debug) {
|
|
374
|
+
console.info("[PayKit] Creating account holder", context, data);
|
|
375
|
+
}
|
|
376
|
+
const { customer, account_holder } = context;
|
|
377
|
+
if (account_holder?.data?.id) {
|
|
378
|
+
return { id: account_holder.data.id };
|
|
379
|
+
}
|
|
380
|
+
if (!customer) {
|
|
381
|
+
throw new utils.MedusaError(
|
|
382
|
+
utils.MedusaError.Types.INVALID_DATA,
|
|
383
|
+
"Customer not found in context"
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
const [accountHolderResult, accountHolderError] = await core.tryCatchAsync(
|
|
387
|
+
this.paykit.customers.create({
|
|
388
|
+
email: customer.email,
|
|
389
|
+
name: customer.email.split("@")[0],
|
|
390
|
+
phone: customer.phone,
|
|
391
|
+
metadata: {
|
|
392
|
+
PAYKIT_METADATA_KEY: JSON.stringify({ source: "medusa-paykit-adapter" })
|
|
393
|
+
}
|
|
394
|
+
})
|
|
395
|
+
);
|
|
396
|
+
if (accountHolderError) {
|
|
397
|
+
throw new utils.MedusaError(
|
|
398
|
+
utils.MedusaError.Types.PAYMENT_AUTHORIZATION_ERROR,
|
|
399
|
+
accountHolderError.message
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
return {
|
|
403
|
+
id: accountHolderResult.id,
|
|
404
|
+
data: accountHolderResult
|
|
405
|
+
};
|
|
406
|
+
};
|
|
407
|
+
updateAccountHolder = async ({
|
|
408
|
+
context,
|
|
409
|
+
data
|
|
410
|
+
}) => {
|
|
411
|
+
if (this.options.debug) {
|
|
412
|
+
console.info("[PayKit] Updating account holder", context, data);
|
|
413
|
+
}
|
|
414
|
+
const { account_holder, customer, idempotency_key } = context;
|
|
415
|
+
if (!account_holder.data?.id) {
|
|
416
|
+
throw new utils.MedusaError(
|
|
417
|
+
utils.MedusaError.Types.INVALID_DATA,
|
|
418
|
+
"Account holder not found in context"
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
if (!customer) {
|
|
422
|
+
return {};
|
|
423
|
+
}
|
|
424
|
+
const accountHolderId = account_holder.data.id;
|
|
425
|
+
const [accountHolderResult, accountHolderError] = await core.tryCatchAsync(
|
|
426
|
+
this.paykit.customers.update(accountHolderId, {
|
|
427
|
+
email: customer.email,
|
|
428
|
+
name: customer.email.split("@")[0],
|
|
429
|
+
phone: customer.phone,
|
|
430
|
+
...data?.metadata && {
|
|
431
|
+
metadata: core.stringifyMetadataValues(
|
|
432
|
+
data?.metadata ?? {}
|
|
433
|
+
)
|
|
434
|
+
}
|
|
435
|
+
})
|
|
436
|
+
);
|
|
437
|
+
if (accountHolderError) {
|
|
438
|
+
throw new utils.MedusaError(
|
|
439
|
+
utils.MedusaError.Types.PAYMENT_AUTHORIZATION_ERROR,
|
|
440
|
+
accountHolderError.message
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
return { data: accountHolderResult };
|
|
444
|
+
};
|
|
445
|
+
deleteAccountHolder = async ({
|
|
446
|
+
context,
|
|
447
|
+
data
|
|
448
|
+
}) => {
|
|
449
|
+
if (this.options.debug) {
|
|
450
|
+
console.info("[PayKit] Deleting account holder", context, data);
|
|
451
|
+
}
|
|
452
|
+
const { account_holder } = context;
|
|
453
|
+
if (!account_holder.data?.id) {
|
|
454
|
+
throw new utils.MedusaError(
|
|
455
|
+
utils.MedusaError.Types.INVALID_DATA,
|
|
456
|
+
"Account holder not found in context"
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
const accountHolderId = account_holder.data.id;
|
|
460
|
+
const [accountHolderResult, accountHolderError] = await core.tryCatchAsync(
|
|
461
|
+
this.paykit.customers.delete(accountHolderId)
|
|
462
|
+
);
|
|
463
|
+
if (accountHolderError) {
|
|
464
|
+
throw new utils.MedusaError(
|
|
465
|
+
utils.MedusaError.Types.PAYMENT_AUTHORIZATION_ERROR,
|
|
466
|
+
accountHolderError.message
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
return { data: accountHolderResult };
|
|
470
|
+
};
|
|
369
471
|
};
|
|
370
472
|
|
|
371
473
|
exports.PaykitMedusaJSAdapter = PaykitMedusaJSAdapter;
|
|
@@ -364,6 +364,108 @@ var PaykitMedusaJSAdapter = class extends AbstractPaymentProvider {
|
|
|
364
364
|
});
|
|
365
365
|
return webhookEvents;
|
|
366
366
|
};
|
|
367
|
+
createAccountHolder = async ({
|
|
368
|
+
context,
|
|
369
|
+
data
|
|
370
|
+
}) => {
|
|
371
|
+
if (this.options.debug) {
|
|
372
|
+
console.info("[PayKit] Creating account holder", context, data);
|
|
373
|
+
}
|
|
374
|
+
const { customer, account_holder } = context;
|
|
375
|
+
if (account_holder?.data?.id) {
|
|
376
|
+
return { id: account_holder.data.id };
|
|
377
|
+
}
|
|
378
|
+
if (!customer) {
|
|
379
|
+
throw new MedusaError(
|
|
380
|
+
MedusaError.Types.INVALID_DATA,
|
|
381
|
+
"Customer not found in context"
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
const [accountHolderResult, accountHolderError] = await tryCatchAsync(
|
|
385
|
+
this.paykit.customers.create({
|
|
386
|
+
email: customer.email,
|
|
387
|
+
name: customer.email.split("@")[0],
|
|
388
|
+
phone: customer.phone,
|
|
389
|
+
metadata: {
|
|
390
|
+
PAYKIT_METADATA_KEY: JSON.stringify({ source: "medusa-paykit-adapter" })
|
|
391
|
+
}
|
|
392
|
+
})
|
|
393
|
+
);
|
|
394
|
+
if (accountHolderError) {
|
|
395
|
+
throw new MedusaError(
|
|
396
|
+
MedusaError.Types.PAYMENT_AUTHORIZATION_ERROR,
|
|
397
|
+
accountHolderError.message
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
return {
|
|
401
|
+
id: accountHolderResult.id,
|
|
402
|
+
data: accountHolderResult
|
|
403
|
+
};
|
|
404
|
+
};
|
|
405
|
+
updateAccountHolder = async ({
|
|
406
|
+
context,
|
|
407
|
+
data
|
|
408
|
+
}) => {
|
|
409
|
+
if (this.options.debug) {
|
|
410
|
+
console.info("[PayKit] Updating account holder", context, data);
|
|
411
|
+
}
|
|
412
|
+
const { account_holder, customer, idempotency_key } = context;
|
|
413
|
+
if (!account_holder.data?.id) {
|
|
414
|
+
throw new MedusaError(
|
|
415
|
+
MedusaError.Types.INVALID_DATA,
|
|
416
|
+
"Account holder not found in context"
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
if (!customer) {
|
|
420
|
+
return {};
|
|
421
|
+
}
|
|
422
|
+
const accountHolderId = account_holder.data.id;
|
|
423
|
+
const [accountHolderResult, accountHolderError] = await tryCatchAsync(
|
|
424
|
+
this.paykit.customers.update(accountHolderId, {
|
|
425
|
+
email: customer.email,
|
|
426
|
+
name: customer.email.split("@")[0],
|
|
427
|
+
phone: customer.phone,
|
|
428
|
+
...data?.metadata && {
|
|
429
|
+
metadata: stringifyMetadataValues(
|
|
430
|
+
data?.metadata ?? {}
|
|
431
|
+
)
|
|
432
|
+
}
|
|
433
|
+
})
|
|
434
|
+
);
|
|
435
|
+
if (accountHolderError) {
|
|
436
|
+
throw new MedusaError(
|
|
437
|
+
MedusaError.Types.PAYMENT_AUTHORIZATION_ERROR,
|
|
438
|
+
accountHolderError.message
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
return { data: accountHolderResult };
|
|
442
|
+
};
|
|
443
|
+
deleteAccountHolder = async ({
|
|
444
|
+
context,
|
|
445
|
+
data
|
|
446
|
+
}) => {
|
|
447
|
+
if (this.options.debug) {
|
|
448
|
+
console.info("[PayKit] Deleting account holder", context, data);
|
|
449
|
+
}
|
|
450
|
+
const { account_holder } = context;
|
|
451
|
+
if (!account_holder.data?.id) {
|
|
452
|
+
throw new MedusaError(
|
|
453
|
+
MedusaError.Types.INVALID_DATA,
|
|
454
|
+
"Account holder not found in context"
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
const accountHolderId = account_holder.data.id;
|
|
458
|
+
const [accountHolderResult, accountHolderError] = await tryCatchAsync(
|
|
459
|
+
this.paykit.customers.delete(accountHolderId)
|
|
460
|
+
);
|
|
461
|
+
if (accountHolderError) {
|
|
462
|
+
throw new MedusaError(
|
|
463
|
+
MedusaError.Types.PAYMENT_AUTHORIZATION_ERROR,
|
|
464
|
+
accountHolderError.message
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
return { data: accountHolderResult };
|
|
468
|
+
};
|
|
367
469
|
};
|
|
368
470
|
|
|
369
471
|
export { PaykitMedusaJSAdapter };
|