Guest User

Untitled

a guest
Jun 22nd, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. <?php
  2. final class Payment {
  3. public function subscribe(array $transaction) : array {
  4. // 1
  5. $transaction = [
  6. 'payment_method' => $transaction['payment_method'] ?? 'credit-card',
  7. 'amount' => $transaction['total'] ?? $transaction['subtotal'] ?? 0.0,
  8. 'currency' => $transaction['currency_code'] ?? 'USD'
  9. ] + $transaction;
  10. $model = new TransactionModel();
  11. $model->create($transaction);
  12.  
  13. // 2
  14. $processor = $model->getProcessor($transaction);
  15. $transaction['processor_id'] = $processor['id'] ?? null;
  16.  
  17. // 3
  18. $status = $model->process($transaction);
  19. $transaction['status'] = $status['success'] ?? false;
  20.  
  21. // 4
  22. unset($transaction['card-number'], $transaction['ccv']);
  23. return $transaction;
  24. }
  25. }
Add Comment
Please, Sign In to add comment