Skip to content

Commit 89f4b88

Browse files
committed
Added get_purchase() API function and tests
1 parent 84e0fe6 commit 89f4b88

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

src/ConvertKit_API.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,23 @@ public function list_purchases(array $options)
610610
return $this->get('purchases', $options);
611611
}
612612

613+
/**
614+
* Retuns a specific purchase.
615+
*
616+
* @param integer $purchase_id Purchase ID.
617+
*
618+
* @return false|object
619+
*/
620+
public function get_purchase(int $purchase_id)
621+
{
622+
return $this->get(
623+
sprintf('purchases/%s', $purchase_id),
624+
[
625+
'api_secret' => $this->api_secret,
626+
]
627+
);
628+
}
629+
613630
/**
614631
* Creates a purchase.
615632
*

tests/ConvertKitAPITest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,41 @@ public function testListPurchases()
712712
$this->assertArrayHasKey('purchases', get_object_vars($purchases));
713713
}
714714

715+
/**
716+
* Test that get_purchases() returns the expected data.
717+
*
718+
* @since 1.0.0
719+
*
720+
* @return void
721+
*/
722+
public function testGetPurchase()
723+
{
724+
// Get ID of first purchase.
725+
$purchases = $this->api->list_purchases([
726+
'page' => 1,
727+
]);
728+
$id = $purchases->purchases[0]->id;
729+
730+
// Get purchase.
731+
$result = $this->api->get_purchase($id);
732+
$this->assertInstanceOf('stdClass', $result);
733+
$this->assertEquals($result->id, $id);
734+
}
735+
736+
/**
737+
* Test that get_purchases() throws a ClientException when an invalid
738+
* purchase ID is specified.
739+
*
740+
* @since 1.0.0
741+
*
742+
* @return void
743+
*/
744+
public function testGetPurchaseWithInvalidID()
745+
{
746+
$this->expectException(GuzzleHttp\Exception\ClientException::class);
747+
$this->api->get_purchase(12345);
748+
}
749+
715750
/**
716751
* Test that create_purchase() returns the expected data.
717752
*

0 commit comments

Comments
 (0)