From 8c368b05abd8338d275c8a98ef904fc4533a50e8 Mon Sep 17 00:00:00 2001 From: Nate Harris Date: Wed, 10 Apr 2024 10:59:01 -0600 Subject: [PATCH] - Only use payment method object type to determine payment method type --- lib/EasyPost/Service/BillingService.php | 4 +-- test/EasyPost/BillingTest.php | 41 ------------------------- 2 files changed, 2 insertions(+), 43 deletions(-) diff --git a/lib/EasyPost/Service/BillingService.php b/lib/EasyPost/Service/BillingService.php index 33ab3a1..0cdab4f 100644 --- a/lib/EasyPost/Service/BillingService.php +++ b/lib/EasyPost/Service/BillingService.php @@ -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); diff --git a/test/EasyPost/BillingTest.php b/test/EasyPost/BillingTest.php index 5ea575f..e829fe0 100644 --- a/test/EasyPost/BillingTest.php +++ b/test/EasyPost/BillingTest.php @@ -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'); - } - } }