File tree Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change 3
3
### Unreleased
4
4
5
5
* [ Breaking] Remove default ` type ` for Stripe Merchant Account creation
6
+ * Refactor ` Pay.sync(params) ` into a Hash for easily extending
7
+
8
+ ``` ruby
9
+ Pay ::SYNC_HANDLERS [:foo ] = -> (id) { Pay ::Foo .sync_checkout(id) }
10
+ # Pay.sync(params) calls lambda if params[:foo] is present
11
+ ```
6
12
7
13
### 8.3.0
8
14
Original file line number Diff line number Diff line change @@ -132,13 +132,20 @@ def self.resolve_option(option, *remaining_args)
132
132
end
133
133
end
134
134
135
+ SYNC_HANDLERS = {
136
+ lemon_squeezy_order_id : -> ( param ) { Pay ::LemonSqueezy . sync_order ( param ) } ,
137
+ paddle_billing_transaction_id : -> ( param ) { Pay ::PaddleBilling . sync_transaction ( param ) } ,
138
+ stripe_checkout_session_id : -> ( param ) { Pay ::Stripe . sync_checkout_session ( param ) } ,
139
+ transaction_id : -> ( param ) { Pay ::PaddleBilling . sync_transaction ( param ) } ,
140
+ session_id : -> ( param ) { Pay ::Stripe . sync_checkout_session ( param ) }
141
+ }
142
+
135
143
def self . sync ( params )
136
- if ( session_id = params [ :stripe_checkout_session_id ] || params [ :session_id ] )
137
- Pay ::Stripe . sync_checkout_session ( session_id )
138
- elsif ( transaction_id = params [ :paddle_billing_transaction_id ] || params [ :transaction_id ] )
139
- Pay ::PaddleBilling . sync_transaction ( transaction_id )
140
- elsif ( order_id = params [ :lemon_squeezy_order_id ] )
141
- Pay ::LemonSqueezy . sync_order ( order_id )
144
+ SYNC_HANDLERS . each do |param_name , handler |
145
+ if ( param = params [ param_name ] )
146
+ return handler . call ( param )
147
+ end
142
148
end
149
+ nil
143
150
end
144
151
end
You can’t perform that action at this time.
0 commit comments