Skip to content

Commit

Permalink
Added support of customer information to charges
Browse files Browse the repository at this point in the history
  • Loading branch information
chinleung committed Feb 5, 2021
1 parent 41cb3d6 commit 111e587
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 23 deletions.
13 changes: 11 additions & 2 deletions src/Builders/ChargeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

use ChinLeung\Converge\Charge;
use ChinLeung\Converge\Client;
use ChinLeung\Converge\Concerns\HasCustomer;
use ChinLeung\Converge\Contracts\Chargeable;
use ChinLeung\Converge\Exceptions\CardException;

class ChargeBuilder extends Builder
{
use HasCustomer;

/**
* The chargeable for the transaction.
*
Expand Down Expand Up @@ -56,13 +59,19 @@ public function chargeable(Chargeable $chargeable): self
*/
public function create(): Charge
{
$response = resolve(Client::class)->send('ccsale', array_merge(
$payload = array_merge(
$this->chargeable->toPayload(),
$this->options,
[
'ssl_amount' => $this->amount / 100,
]
));
);

if ($this->customer) {
$payload = array_merge($payload, $this->customer->toPayload());
}

$response = resolve(Client::class)->send('ccsale', $payload);

if ($response->get('ssl_result') === '1') {
throw new CardException($response->get('ssl_result_message'));
Expand Down
24 changes: 3 additions & 21 deletions src/Builders/TokenBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,20 @@

use ChinLeung\Converge\Card;
use ChinLeung\Converge\Client;
use ChinLeung\Converge\Customer;
use ChinLeung\Converge\Concerns\HasCustomer;
use ChinLeung\Converge\Token;

class TokenBuilder extends Builder
{
use HasCustomer;

/**
* The card that should be used for the token.
*
* @var \ChinLeung\Converge\Card
*/
protected $card;

/**
* The customer of the card.
*
* @var \ChinLeung\Converge\Customer
*/
protected $customer;

/**
* Set the card of the token.
*
Expand Down Expand Up @@ -56,19 +51,6 @@ public function create(): Token
return Token::make($response->get('ssl_token'));
}

/**
* Set the customer of the token.
*
* @param \ChinLeung\Converge\Customer $customer
* @return self
*/
public function customer(Customer $customer): self
{
$this->customer = $customer;

return $this;
}

/**
* Save the token.
*
Expand Down
28 changes: 28 additions & 0 deletions src/Concerns/HasCustomer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace ChinLeung\Converge\Concerns;

use ChinLeung\Converge\Customer;

trait HasCustomer
{
/**
* The customer of the card.
*
* @var \ChinLeung\Converge\Customer
*/
protected $customer;

/**
* Set the customer of the token.
*
* @param \ChinLeung\Converge\Customer $customer
* @return self
*/
public function customer(Customer $customer): self
{
$this->customer = $customer;

return $this;
}
}

0 comments on commit 111e587

Please sign in to comment.