Skip to content

Commit

Permalink
Add method for taxes when creating subscription.
Browse files Browse the repository at this point in the history
  • Loading branch information
srmklive committed Aug 22, 2023
1 parent 850008e commit ceae395
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Traits/PayPalAPI/Subscriptions/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ trait Helpers
*/
protected $cancel_url;

/**
* @var array
*/
protected $taxes;

/**
* Setup a subscription.
*
Expand Down Expand Up @@ -97,6 +102,10 @@ public function setupSubscription(string $customer_name, string $customer_email,
];
}

if (isset($this->taxes)) {
$body['taxes'] = $this->taxes;
}

$subscription = $this->createSubscription($body);

unset($this->product);
Expand Down Expand Up @@ -471,4 +480,21 @@ public function addShippingAddress(string $full_name, string $address_line_1, st

return $this;
}

/**
* Add taxes when creating a subscription.
*
* @param float $price
*
* @return \Srmklive\PayPal\Services\PayPal
*/
public function addTaxes(float $percentage)
{
$this->taxes = [
'percentage' => $percentage,
'inclusive' => false,
];

return $this;
}
}
28 changes: 28 additions & 0 deletions tests/Feature/AdapterCreateSubscriptionHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,4 +541,32 @@ public function it_can_add_custom_payment_failure_threshold_value_when_creating_
$this->assertArrayHasKey('id', $response);
$this->assertArrayHasKey('plan_id', $response);
}

/** @test */
public function it_can_set_tax_percentage_when_creating_subscription()
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);

$start_date = Carbon::now()->addDay()->toDateString();
$percentage = 10;

$this->client = $this->client->addTaxes($percentage)
->addProductById('PROD-XYAB12ABSB7868434')
->addBillingPlanById('P-5ML4271244454362WXNWU5NQ');

$this->client->setClient(
$this->mock_http_client(
$this->mockCreateSubscriptionResponse()
)
);

$response = $this->client->setupSubscription('John Doe', '[email protected]', $start_date);

$this->assertNotEmpty($response);
$this->assertArrayHasKey('id', $response);
$this->assertArrayHasKey('plan_id', $response);
}
}

0 comments on commit ceae395

Please sign in to comment.