@@ -63,25 +63,30 @@ class Invoice extends RecurlyData {
6363
6464 fetchPDF ( callback ) {
6565 if ( ! this . href ) {
66- throw ( new Error ( 'cannot fetch a record without an href' ) )
66+ throw new Error ( 'cannot fetch a record without an href' )
6767 }
6868
69- this . get ( this . href , { } , {
70- headers : {
71- Accept : 'application/pdf'
69+ this . get (
70+ this . href ,
71+ { } ,
72+ {
73+ headers : {
74+ Accept : 'application/pdf'
75+ } ,
76+ encoding : null ,
77+ noParse : true
7278 } ,
73- encoding : null ,
74- noParse : true
75- } , ( err , response , payload ) => {
76- if ( err ) {
77- return callback ( err )
79+ ( err , response , payload ) => {
80+ if ( err ) {
81+ return callback ( err )
82+ }
83+ if ( response . statusCode === 404 ) {
84+ return callback ( new Error ( 'not_found' ) )
85+ }
86+
87+ callback ( err , payload )
7888 }
79- if ( response . statusCode === 404 ) {
80- return callback ( new Error ( 'not_found' ) )
81- }
82-
83- callback ( err , payload )
84- } )
89+ )
8590 }
8691
8792 refund ( options , callback ) {
@@ -90,16 +95,20 @@ class Invoice extends RecurlyData {
9095 options = null
9196 }
9297
93- options = _ . defaults ( {
94- amount_in_cents : undefined ,
95- refund_apply_order : undefined
96- } , options , { refund_apply_order : 'credit' } )
98+ options = _ . defaults (
99+ {
100+ amount_in_cents : undefined ,
101+ refund_method : undefined
102+ } ,
103+ options ,
104+ { refund_method : 'credit_first' }
105+ )
97106
98107 debug ( 'Got options as %o' , options )
99108
100109 let uri = _ . get ( this , 'a.refund.href' )
101110 if ( ! uri && ! this . invoice_number ) {
102- throw ( new Error ( 'cannot refund an invoice without an invoice_number' ) )
111+ throw new Error ( 'cannot refund an invoice without an invoice_number' )
103112 }
104113
105114 uri = uri || `${ Invoice . ENDPOINT } /${ this . invoice_number } /refund`
@@ -108,7 +117,7 @@ class Invoice extends RecurlyData {
108117 debug ( 'Calling refund uri %s with body %o' , uri , body )
109118
110119 this . post ( uri , body , ( err , response , payload ) => {
111- const error = handleRecurlyError ( err , response , payload , [ 201 ] )
120+ const error = handleRecurlyError ( err , response , payload , [ 201 ] )
112121 if ( error ) {
113122 return callback ( error )
114123 }
@@ -120,13 +129,15 @@ class Invoice extends RecurlyData {
120129 markSuccessful ( callback ) {
121130 let uri = _ . get ( this , 'a.mark_successful.href' )
122131 if ( ! uri && ! this . invoice_number ) {
123- throw ( new Error ( 'cannot mark invoice as successful without an invoice_number' ) )
132+ throw new Error (
133+ 'cannot mark invoice as successful without an invoice_number'
134+ )
124135 }
125136
126137 uri = uri || `${ Invoice . ENDPOINT } /${ this . invoice_number } /mark_successful`
127138
128139 this . put ( uri , null , ( err , response , payload ) => {
129- const error = handleRecurlyError ( err , response , payload , [ 200 ] )
140+ const error = handleRecurlyError ( err , response , payload , [ 200 ] )
130141 if ( error ) {
131142 return callback ( error )
132143 }
@@ -138,13 +149,13 @@ class Invoice extends RecurlyData {
138149 markFailed ( callback ) {
139150 let uri = _ . get ( this , 'a.mark_failed.href' )
140151 if ( ! uri && ! this . invoice_number ) {
141- throw ( new Error ( 'cannot mark invoice as failed without an invoice_number' ) )
152+ throw new Error ( 'cannot mark invoice as failed without an invoice_number' )
142153 }
143154
144155 uri = uri || `${ Invoice . ENDPOINT } /${ this . invoice_number } /mark_failed`
145156
146157 this . put ( uri , null , ( err , response , payload ) => {
147- const error = handleRecurlyError ( err , response , payload , [ 200 ] )
158+ const error = handleRecurlyError ( err , response , payload , [ 200 ] )
148159 if ( error ) {
149160 return callback ( error )
150161 }
0 commit comments