Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Pay/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ abstract public function getPaymentMethod(string $customerId, string $paymentMet
*/
abstract public function createFuturePayment(string $customerId, array $paymentMethodTypes = []): array;

/**
* Calculate tax based on address
*
* @param string $invoiceId
* @param float $amount
* @param string $currency
* @param array $address
* @return array
*/
abstract public function taxCalculations(string $invoiceId, float $amount, string $currency, array $address): array;

/**
* Call
* Make a request
Expand Down
25 changes: 25 additions & 0 deletions src/Pay/Adapter/Stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,31 @@ public function createFuturePayment(string $customerId, array $paymentMethodType
return $result;
}

public function taxCalculations(string $invoiceId, float $amount, string $currency, array $address): array
{
$path = '/tax/calculations';

$lineItems = [
0 => [
'amount' => $amount,
'reference' => $invoiceId,
]
];
$customerDetails = [
'address' => $address,
'address_source' => 'billing',
];
$requestBody = [
'currency' => $currency,
'customer_details' => $customerDetails,
'line_items' => $lineItems
];

$result = $this->execute(self::METHOD_POST, $path, $requestBody);

return $result;
}

private function execute(string $method, string $path, array $requestBody = [], array $headers = []): array
{
$headers = array_merge(['content-type' => 'application/x-www-form-urlencoded', 'Authorization' => 'Bearer '.$this->secretKey], $headers);
Expand Down
5 changes: 5 additions & 0 deletions src/Pay/Pay.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ public function deleteCustomer(string $customerId): bool
return $this->adapter->deleteCustomer($customerId);
}

public function taxCalculations(string $invoiceId, float $amount, string $currency, array $address): array
{
return $this->adapter->taxCalculations($invoiceId, $amount, $currency, $address);
}

/**
* Create Setup for accepting future payments
*
Expand Down
12 changes: 12 additions & 0 deletions tests/Pay/Adapter/StripeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ public function testDeletePaymentMethod(array $data)
$this->stripe->getPaymentMethod($customerId, $data['paymentMethodId']);
}

public function testTaxCalculations()
{
// $res = $this->stripe->taxCalculations('test1', 2000, 'USD', [
// 'line1' => '354 Oyster Point Blvd',
// 'line2' => '',
// 'postal_code' => '94080',
// 'state' => 'CA',
// 'country' => 'US',
// ], );
// var_dump($res);
}

/** @depends testUpdateCustomer */
public function testDeleteCustomer(array $data)
{
Expand Down