### An Vo | Anuska pair programming
#### 23Sep21
```
1. fake the omise response, list of charge_id (1, 2 charges)
Omise::Request::CreateCharge.start_faking!(:success)
=> return the block of add_fake_response(:success) {
[
{ charge_id: `chrg_123`}
{ charge_id: `chrg_1234`}
]
}
2. fake the order_id which generated from Xfers ( payment_service)
res = [
{ charge_id: `chrg_123`, order_id: `order_123`}
{ charge_id: `chrg_1234`, order_id: `order_1234`}
]
allow(OmiseJob).to receive(:new).and_return(res)
3. U map those 2 item together
```
1. How to link a Omise list charge report with Order from payment service ?
Input
[
{ charge_id: "chrg_1", ...},
{ charge_id: "chrg_2", ...}
]
a. Hard way
=>
`PaymentInstructions` / OmisePaymentMethodData
=>
`PaymentMethod`
=> .... Order
b. Easier way
- [x] Create new column `PaymentInstructions.order_identifier`
- in `cbmt/payments_api.rb#` - `post "payments"`
```
payment_instruction = payment_instruction_klass.persist_payment(wrapped_response, accounts_service_provider: accounts_service_provider) # should return an instance of payment_instructions
result = payment_instruction_klass.payment_service_klass.create_one_off_payment!(...
)
order_id = result[:order_id] # Psedocode - result should contain order_id information
payment_instruction.update!(order_identifir: order_id)
```
```
def find_order(charge_id)
pi = PaymentInstruction.find_by payment_identifier: charge_id
pi.order_identifier
```
=> Output
[
{order_1},
{order_2}
]
### Archived
### Omise settlement report brainstorm
1. Omise List charges
[{
charge_id1,
amt1
},
{
charge_id2,
amt2
}
]
2. Periodically fetch 1) from Omise:
Report (Format ?) - No need to define new active record, can be a data collection in applciation code
\_ Row1 (Format ?) => ExternalLedger
\_ Row2
3. Reference to TIm's PR to define the format of Report / Row
4. How to create SettlementReport
```
# Dump class to serialize Omise list charge response to rows (???)
class SettlementReport
def initialize(response)
@response = response
end
def rows
@response.map do |res|
{
id: res[:xxx],
amount: res[:amountyyy],
}
end
end
end
```
5. How to transfrom a list_charge to SettlementReport
a) Schedule a job to periodically fetch list_charge response from Omise (assume 10 minutes) `OmiseSettlementJob`
b) with OmiseSettlementJob:
```
fetched_response = Omise::Client.list_charge(from:, to:)
report = SettlementReport.new(fetched_response) # Teach SEttlementReport to recognize the response
report.rows # => Can fetch enough data
PaymentService.settle_payment!(report)
```
Concerns:
1. How to format report class ?
2. HOw to serialize `report.rows` ?