@commercetools/connect-payments-sdk 0.2.1 → 0.2.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @commercetools/connect-payments-sdk
2
2
 
3
+ ## 0.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - b87b064: added support for retrieving the merchant return url from the session
8
+
3
9
  ## 0.2.1
4
10
 
5
11
  ### Patch Changes
@@ -14,4 +14,5 @@ export declare class DefaultCartService implements CartService {
14
14
  private calculateTotalPaidAmount;
15
15
  private calculatePaymentAmount;
16
16
  private wasPaymentReverted;
17
+ private isPaymentApproved;
17
18
  }
@@ -82,14 +82,18 @@ class DefaultCartService {
82
82
  if (this.wasPaymentReverted(payment)) {
83
83
  return 0;
84
84
  }
85
- return payment.transactions
86
- .filter((transaction) => (transaction.state === 'Success' || transaction.state === 'Pending') &&
87
- (transaction.type === 'Authorization' || transaction.type === 'Charge'))
88
- .reduce((total, transaction) => total + transaction.amount.centAmount, 0);
85
+ if (this.isPaymentApproved(payment)) {
86
+ return payment.amountPlanned.centAmount;
87
+ }
88
+ return 0;
89
89
  }
90
90
  wasPaymentReverted(payment) {
91
91
  return payment.transactions.some((tx) => (tx.type === 'CancelAuthorization' || tx.type === 'Refund') &&
92
92
  (tx.state === 'Success' || tx.state === 'Pending'));
93
93
  }
94
+ isPaymentApproved(payment) {
95
+ return payment.transactions.some((transaction) => (transaction.state === 'Success' || transaction.state === 'Pending') &&
96
+ (transaction.type === 'Authorization' || transaction.type === 'Charge'));
97
+ }
94
98
  }
95
99
  exports.DefaultCartService = DefaultCartService;
@@ -15,4 +15,5 @@ export declare class DefaultSessionService implements SessionService {
15
15
  getAllowedPaymentMethodsFromSession(session: Session): string[];
16
16
  getProcessorUrlFromSession(session: Session): string;
17
17
  getPaymentInterfaceFromSession(session: Session): string | undefined;
18
+ getMerchantReturnUrlFromSession(session: Session): string | undefined;
18
19
  }
@@ -47,5 +47,8 @@ class DefaultSessionService {
47
47
  getPaymentInterfaceFromSession(session) {
48
48
  return session.metadata?.paymentInterface;
49
49
  }
50
+ getMerchantReturnUrlFromSession(session) {
51
+ return session.metadata?.merchantReturnUrl;
52
+ }
50
53
  }
51
54
  exports.DefaultSessionService = DefaultSessionService;
@@ -27,4 +27,5 @@ export interface SessionService {
27
27
  getAllowedPaymentMethodsFromSession(session: Session): string[];
28
28
  getProcessorUrlFromSession(session: Session): string;
29
29
  getPaymentInterfaceFromSession(session: Session): string | undefined;
30
+ getMerchantReturnUrlFromSession(session: Session): string | undefined;
30
31
  }
@@ -17,6 +17,7 @@ class SessionAuthenticationManager {
17
17
  allowedPaymentMethods: this.sessionService.getAllowedPaymentMethodsFromSession(session),
18
18
  processorUrl: this.sessionService.getProcessorUrlFromSession(session),
19
19
  paymentInterface: this.sessionService.getPaymentInterfaceFromSession(session),
20
+ merchantReturnUrl: this.sessionService.getMerchantReturnUrlFromSession(session),
20
21
  });
21
22
  }
22
23
  catch (e) {
@@ -17,6 +17,7 @@ export type SessionPrincipal = {
17
17
  allowedPaymentMethods: string[];
18
18
  processorUrl: string;
19
19
  paymentInterface?: string;
20
+ merchantReturnUrl?: string;
20
21
  };
21
22
  export type Oauth2Principal = {
22
23
  clientId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools/connect-payments-sdk",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Payment SDK for commercetools payment connectors",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  ],
16
16
  "license": "ISC",
17
17
  "dependencies": {
18
- "@commercetools/platform-sdk": "7.3.0",
18
+ "@commercetools/platform-sdk": "7.4.0",
19
19
  "@commercetools/sdk-client-v2": "2.3.0",
20
20
  "jsonwebtoken": "9.0.2",
21
21
  "jwks-rsa": "3.1.0"