Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| Transaction_Formatter | |
0.00% |
0 / 18 |
|
0.00% |
0 / 4 |
30 | |
0.00% |
0 / 1 |
| get_url | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| get_ellipses | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_order_note | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
| get_note_part | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BrianHenryIE\WP_Bitcoin_Gateway\API; |
| 4 | |
| 5 | use BrianHenryIE\WP_Bitcoin_Gateway\API\Model\Transaction_Interface; |
| 6 | |
| 7 | class Transaction_Formatter { |
| 8 | |
| 9 | |
| 10 | public function get_url( Transaction_Interface $transaction ): string { |
| 11 | return sprintf( |
| 12 | 'https://blockchain.com/explorer/transactions/btc/%s', |
| 13 | $transaction->get_txid() |
| 14 | ); |
| 15 | } |
| 16 | |
| 17 | public function get_ellipses( Transaction_Interface $transaction ): string { |
| 18 | return substr( $transaction->get_txid(), 0, 3 ) . '...' . substr( $transaction->get_txid(), - 3 ); |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * @param Transaction_Interface[] $new_order_transactions |
| 23 | * |
| 24 | * @return string |
| 25 | */ |
| 26 | public function get_order_note( array $new_order_transactions ): string { |
| 27 | |
| 28 | $note = ''; |
| 29 | // TODO: plural. |
| 30 | $note .= 'New transactions seen: '; |
| 31 | $new_transactions_notes = array(); |
| 32 | foreach ( $new_order_transactions as $new_transaction ) { |
| 33 | $new_transactions_notes[] = $this->get_note_part( $new_transaction ); |
| 34 | } |
| 35 | $note .= implode( ',', $new_transactions_notes ) . ".\n\n"; |
| 36 | |
| 37 | return $note; |
| 38 | } |
| 39 | |
| 40 | protected function get_note_part( Transaction_Interface $transaction ): string { |
| 41 | return sprintf( |
| 42 | '<a href="%s" target="_blank">%s</a>, @%s', |
| 43 | esc_url( $this->get_url( $transaction ) ), |
| 44 | $this->get_ellipses( $transaction ), |
| 45 | $transaction->get_block_height() ?? 'mempool' |
| 46 | ); |
| 47 | } |
| 48 | } |