Skip to content

Commit

Permalink
- Only use payment method object type to determine payment method type
Browse files Browse the repository at this point in the history
  • Loading branch information
nwithan8 committed Apr 10, 2024
1 parent 09fa160 commit 8c368b0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 43 deletions.
4 changes: 2 additions & 2 deletions lib/EasyPost/Service/BillingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ private function getPaymentInfo(string $priority = 'primary'): array
if ($paymentMethodToUse != null && $paymentMethods->$paymentMethodToUse->id != null) {
$paymentMethodId = $paymentMethods->$paymentMethodToUse->id;
$paymentMethodObjectType = $paymentMethods->$paymentMethodToUse->object;
if (str_starts_with($paymentMethodId, 'card_') || $paymentMethodObjectType == 'CreditCard') {
if ($paymentMethodObjectType == 'CreditCard') {
$endpoint = '/credit_cards';
} else if (str_starts_with($paymentMethodId, 'bank_') || $paymentMethodObjectType == 'BankAccount') {
} else if ($paymentMethodObjectType == 'BankAccount') {
$endpoint = '/bank_accounts';
} else {
throw new PaymentException(Constants::INVALID_PAYMENT_METHOD_ERROR);
Expand Down
41 changes: 0 additions & 41 deletions test/EasyPost/BillingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,45 +313,4 @@ public function testGetPaymentMethodInfoByObjectType(): void
$this->fail('Exception thrown when we expected no error');
}
}

/**
* Test determining the payment method type by legacy ID prefix
*/
public function testGetPaymentMethodInfoByLegacyIdPrefix(): void
{
$mockingUtility = new MockingUtility(
new MockRequest(
new MockRequestMatchRule(
'get',
'/v2\\/payment_methods$/'
),
new MockRequestResponseInfo(
200,
'{"id": "summary_123", "primary_payment_method": {"id": "card_123", "object": null, "last4": "1234"}, "secondary_payment_method": {"id": "bank_123", "object": null, "bank_name": "Mock Bank"}}' // phpcs:ignore
)
),
new MockRequest(
new MockRequestMatchRule(
'delete',
'/v2\\/bank_accounts\\/bank_123$/'
),
new MockRequestResponseInfo(
200,
'{}'
)
),
);
$client = self::getClient($mockingUtility);

// getPaymentInfo is private, but we can test it by attempting to delete a payment method
// only a delete request to /v2/bank_accounts/bank_123 is mocked
// if the delete function works, it's because it found the correct payment method type
try {
$client->billing->deletePaymentMethod('secondary');

$this->assertTrue(true);
} catch (\Exception $exception) {
$this->fail('Exception thrown when we expected no error');
}
}
}

0 comments on commit 8c368b0

Please sign in to comment.