Skip to content

Commit 144249a

Browse files
eugene-syanru
authored andcommitted
Fixes for checkout (#17)
* shipping methods * coupon endpoints * account requests * id as value not string
1 parent 4e3a366 commit 144249a

4 files changed

Lines changed: 50 additions & 2 deletions

File tree

src/api/account.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
}

src/api/cart.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff 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)

src/endpoints.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ export const cartCheckout = '/v1/my/cart/checkout';
1616
export const shippingMethods = '/v1/my/cart/shipping-methods';
1717
export const shippingMethod = '/v1/my/cart/shipping-method';
1818
export const shippingAddress = '/v1/my/cart/shipping-address';
19-
export const shippingAddressId = id => `${shippingAddress}/id`;
19+
export const shippingAddressId = id => `${shippingAddress}/${id}`;
2020
export const cartLineItems = '/v1/my/cart/line-items';
2121
export const cartPaymentCreditCarts = '/v1/my/cart/payment-methods/credit-cards';
2222
export const cartPaymentGiftCards = '/v1/my/cart/payment-methods/gift-cards';
2323
export 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

2527
export const addToCart = '/v1/my/cart/add';
2628

@@ -41,3 +43,6 @@ export const creditCardDefault = creditCardId => `${creditCard(creditCardId)}/de
4143
export const storeCredit = storeCreditId => `/v1/my/payment-methods/store-credits/${storeCreditId}`;
4244
export const storeCreditTotals = `/v1/my/payment-methods/store-credits/totals`;
4345
export const storeCredits = `/search/store_credits_search_view/_search`;
46+
47+
// account endpoints
48+
export const account = '/v1/my/account';

src/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Auth from './api/auth';
1717
import CreditCards from './api/credit-cards';
1818
import StoreCredits from './api/store-credits';
1919
import Cart from './api/cart';
20+
import Account from './api/account';
2021
import jwtDecode from 'jwt-decode';
2122

2223
export 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

0 commit comments

Comments
 (0)