@xsolla/payment-client-core 0.0.7 → 0.0.8

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.
@@ -501,7 +501,7 @@ class TokenError extends AppError {
501
501
  class SubmitRequest extends XpsApiPartRequest {
502
502
  constructor(parameters) {
503
503
  super();
504
- const { token, dfpHash } = parameters;
504
+ const { token, fields, form, dfpHash } = parameters;
505
505
  if (token === null) {
506
506
  throw new TokenError();
507
507
  }
@@ -509,6 +509,14 @@ class SubmitRequest extends XpsApiPartRequest {
509
509
  if (dfpHash) {
510
510
  this.xps_dfp_hash = dfpHash;
511
511
  }
512
+ this.addXpsParameters(this.getFieldsValues(fields, form));
513
+ }
514
+ getFieldsValues(fields, form) {
515
+ return fields.reduce((xpsParams, field) => {
516
+ const formControl = form.get(field.name);
517
+ xpsParams[field.name] = formControl ? formControl.value : field?.value;
518
+ return xpsParams;
519
+ }, {});
512
520
  }
513
521
  }
514
522
 
@@ -817,13 +825,13 @@ class SubmitService {
817
825
  .getHash()
818
826
  // eslint-disable-next-line @typescript-eslint/promise-function-async
819
827
  .then((dfpHash) => {
820
- const request = this.requestFactory({
828
+ const requestParams = this.requestFactory({
821
829
  token: this.settingsService.token,
822
830
  fields,
823
831
  form,
824
832
  dfpHash,
825
833
  });
826
- return lastValueFrom(this.secureApi.post(this.directPaymentApiRoute, request, {
834
+ return lastValueFrom(this.secureApi.post(this.directPaymentApiRoute, new URLSearchParams({ ...requestParams }), {
827
835
  headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'),
828
836
  responseType: 'json',
829
837
  }))
@@ -2406,8 +2414,11 @@ class PaymentService {
2406
2414
  this.syncService.setup(this.form, this.fields);
2407
2415
  return this.fields;
2408
2416
  }
2409
- async submit(fields, form) {
2410
- const submitResponse = await this.submitService.request(fields, form);
2417
+ async submit() {
2418
+ if (!this.form) {
2419
+ throw new Error('form is empty!');
2420
+ }
2421
+ const submitResponse = await this.submitService.request(this.fields, this.form);
2411
2422
  return this.nextActionService.getNextAction(submitResponse);
2412
2423
  }
2413
2424
  getFields() {
@@ -2572,7 +2583,7 @@ class CoreLibraryService {
2572
2583
  createPayment(config) {
2573
2584
  return {
2574
2585
  initialize: async () => this.paymentService.initialize(config),
2575
- submit: async (fields, form) => this.paymentService.submit(fields, form),
2586
+ submit: async () => this.paymentService.submit(),
2576
2587
  getFields: () => this.paymentService.getFields(),
2577
2588
  changeFieldValue: (name, value) => this.paymentService.changeFieldValue(name, value),
2578
2589
  validate: async (field) => this.paymentService.validate(field),