GitHub

DaffPaypalEffects

import { DaffPaypalEffects } from '@daffodil/paypal/state'

@Injectable()
class DaffPaypalEffects<<T extends DaffPaypalExpressTokenRequest, V extends DaffPaypalExpressTokenResponse>>  {
  generatePaypalExpressToken$: Observable<Action> = createEffect(() => this.actions$.pipe(
      ofType(DaffPaypalActionTypes.GeneratePaypalExpressTokenAction),
      switchMap((action: DaffGeneratePaypalExpressToken<T>) => defer(() => of(this.storage.getCartId())).pipe(
        switchMap(cartId => this.driver.generateToken(cartId, action.payload)),
        map((resp: V) => new DaffGeneratePaypalExpressTokenSuccess(resp)),
        catchError((error: DaffError) => of(new DaffGeneratePaypalExpressTokenFailure(this.errorMatcher(error)))),
      )),
    ))
}