Skip to content

Commit

Permalink
Payment with customer
Browse files Browse the repository at this point in the history
  • Loading branch information
mhajdu committed Apr 7, 2023
1 parent e4b38f4 commit 39ce29f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
14 changes: 12 additions & 2 deletions src/Controllers/CustomerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ public function createCustomer($customer) {
'data' => $this->encryptData($body)
]);

return $response->json();
if ($response->successful()) {
return $response->json();
} else {
throw new \Exception($response->json()['message']);
}
}

public function fetchCustomer($customer_id) {
Expand All @@ -52,7 +56,13 @@ public function fetchCustomer($customer_id) {
'data' => $this->encryptData($body)
]);

return $response->json();
if($response->successful()) {
return $response->json();
} else if($response->status() == 404) {
throw new \Exception('Customer not found');
} else {
throw new \Exception($response->json()['message']);
}
}

public function fetchPayments($customer_id) {
Expand Down
16 changes: 9 additions & 7 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,18 @@ public function createPayment($payment) {

public function createPaymentWithCustomer($payment, $customer) {
$customer = $this->customer()->createCustomer($customer);
if($customer['status'] == 'success') {
$payment['customer_id'] = $customer['customer_id'];
if(isset($customer['id'])) {
$payment['customer_id'] = $customer['id'];
$pm = $this->payment()->createPayment($payment);
if($pm->redirect_url) {
echo $pm->redirect_url;
return;
if(isset($pm['payment']['id'])) {
return [
'customer' => $customer,
...$pm
];
}
return $pm;
throw new \Exception('Payment creation failed');
}
return $customer;
throw new \Exception('Customer creation failed');
}

public function getCustomer($customer_id) {
Expand Down

0 comments on commit 39ce29f

Please sign in to comment.