File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+
2+ // @class Account
3+
4+ import * as endpoints from '../endpoints' ;
5+
6+ export default class Account {
7+ constructor ( api ) {
8+ this . api = api ;
9+ }
10+
11+ // @method get(): Promise<LoginResponse>
12+ get ( ) {
13+ return this . api . get ( endpoints . account ) ;
14+ }
15+
16+ // @method update(payload: UpdateCustomerPayload): Promise<LoginResponse>
17+ // Updates account.
18+ update ( payload ) {
19+ return this . api . patch ( endpoints . account , payload ) ;
20+ }
21+ }
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ export default class Cart {
4040 * Chooses shipping method for the cart.
4141 */
4242 chooseShippingMethod ( shippingMethodId ) {
43- return this . api . patch ( endpoints . shippingMethods , { shippingMethodId } ) . then ( normalizeResponse ) ;
43+ return this . api . patch ( endpoints . shippingMethod , { shippingMethodId } ) . then ( normalizeResponse ) ;
4444 }
4545
4646 /**
@@ -191,6 +191,23 @@ export default class Cart {
191191 removeStoreCrdits ( ) {
192192 return this . api . delete ( endpoints . cartPaymentStoreCredits ) . then ( normalizeResponse ) ;
193193 }
194+
195+
196+ /**
197+ * @method addCoupon(code: Number): Promise<FullOrder>
198+ * Adds coupon code to the cart.
199+ */
200+ addCoupon ( code ) {
201+ return this . api . post ( endpoints . cartPaymentCouponCodeWithCode ( code . trim ( ) ) , { } ) . then ( normalizeResponse ) ;
202+ }
203+
204+ /**
205+ * @method removeCoupon(): Promise<FullOrder>
206+ * Removes coupon code of the cart.
207+ */
208+ removeCoupon ( ) {
209+ return this . api . delete ( endpoints . cartPaymentCouponCode ) . then ( normalizeResponse ) ;
210+ }
194211}
195212
196213// @miniclass ItemQuantities (Cart)
Original file line number Diff line number Diff line change @@ -16,11 +16,13 @@ export const cartCheckout = '/v1/my/cart/checkout';
1616export const shippingMethods = '/v1/my/cart/shipping-methods' ;
1717export const shippingMethod = '/v1/my/cart/shipping-method' ;
1818export const shippingAddress = '/v1/my/cart/shipping-address' ;
19- export const shippingAddressId = id => `${ shippingAddress } /id ` ;
19+ export const shippingAddressId = id => `${ shippingAddress } /${ id } ` ;
2020export const cartLineItems = '/v1/my/cart/line-items' ;
2121export const cartPaymentCreditCarts = '/v1/my/cart/payment-methods/credit-cards' ;
2222export const cartPaymentGiftCards = '/v1/my/cart/payment-methods/gift-cards' ;
2323export const cartPaymentStoreCredits = '/v1/my/cart/payment-methods/store-credits' ;
24+ export const cartPaymentCouponCode = '/v1/my/cart/coupon' ;
25+ export const cartPaymentCouponCodeWithCode = code => `/v1/my/cart/coupon/${ code } ` ;
2426
2527export const addToCart = '/v1/my/cart/add' ;
2628
@@ -41,3 +43,6 @@ export const creditCardDefault = creditCardId => `${creditCard(creditCardId)}/de
4143export const storeCredit = storeCreditId => `/v1/my/payment-methods/store-credits/${ storeCreditId } ` ;
4244export const storeCreditTotals = `/v1/my/payment-methods/store-credits/totals` ;
4345export const storeCredits = `/search/store_credits_search_view/_search` ;
46+
47+ // account endpoints
48+ export const account = '/v1/my/account' ;
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import Auth from './api/auth';
1717import CreditCards from './api/credit-cards' ;
1818import StoreCredits from './api/store-credits' ;
1919import Cart from './api/cart' ;
20+ import Account from './api/account' ;
2021import jwtDecode from 'jwt-decode' ;
2122
2223export default class Api {
@@ -49,6 +50,10 @@ export default class Api {
4950 // @property cart: Cart
5051 // Cart instance
5152 this . cart = new Cart ( this ) ;
53+
54+ // @property account: Account
55+ // Account instance
56+ this . account = new Account ( this ) ;
5257 }
5358
5459 // @method addAuth(jwt: String): FoxApi
You can’t perform that action at this time.
0 commit comments