diff --git a/src/Builders/ChargeBuilder.php b/src/Builders/ChargeBuilder.php index 3fed51a..ecf7c0b 100644 --- a/src/Builders/ChargeBuilder.php +++ b/src/Builders/ChargeBuilder.php @@ -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. * @@ -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')); diff --git a/src/Builders/TokenBuilder.php b/src/Builders/TokenBuilder.php index 01fe446..698566d 100644 --- a/src/Builders/TokenBuilder.php +++ b/src/Builders/TokenBuilder.php @@ -4,11 +4,13 @@ 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. * @@ -16,13 +18,6 @@ class TokenBuilder extends Builder */ protected $card; - /** - * The customer of the card. - * - * @var \ChinLeung\Converge\Customer - */ - protected $customer; - /** * Set the card of the token. * @@ -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. * diff --git a/src/Concerns/HasCustomer.php b/src/Concerns/HasCustomer.php new file mode 100644 index 0000000..537fddf --- /dev/null +++ b/src/Concerns/HasCustomer.php @@ -0,0 +1,28 @@ +customer = $customer; + + return $this; + } +}