diff --git a/composer.json b/composer.json index f9f2c45..13dd325 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "lunar/payments-api-sdk", "description": "PHP SDK to communicate with the Lunar HTTP API", - "version": "1.0.0", + "version": "1.0.1", "license": "MIT", "minimum-stability": "dev", "autoload": { diff --git a/src/Endpoint/Payments.php b/src/Endpoint/Payments.php index 4038d51..b698f5f 100644 --- a/src/Endpoint/Payments.php +++ b/src/Endpoint/Payments.php @@ -72,6 +72,24 @@ public function intent($payment_id) return $api_response->json; } + /** + * + * @param $payment_id + * @param $method + * + * @return array + */ + public function updatePreferredPaymentMethod($payment_id, $method) + { + $url = 'payments/' . $payment_id.'/intent/preferredPaymentMethod'; + + $api_response = $this->lunar->client->request('POST', $url, [ + 'preferredPaymentMethod' => $method + ]); + + return $api_response->json; + } + public function submit($payment_id, $args) { $url = 'payments/' . $payment_id.'/submit'; diff --git a/tests/PaymentsTest.php b/tests/PaymentsTest.php index 8f95f4e..4e0d4af 100644 --- a/tests/PaymentsTest.php +++ b/tests/PaymentsTest.php @@ -95,6 +95,21 @@ public function testUpdatePaymentMethod() $this->assertEquals('mobilePay', $payment['selectedPaymentMethod']); } + public function testUpdatePreferred() + { + $response = $this->payments->updatePreferredPaymentMethod($this->payment_id,'card'); + + $payment = $this->payments->fetch($this->payment_id); + + $this->assertEquals('card', $payment['preferredPaymentMethod']); + + $response = $this->payments->updatePreferredPaymentMethod($this->payment_id,'mobilePay'); + + $payment = $this->payments->fetch($this->payment_id); + + $this->assertEquals('mobilePay', $payment['preferredPaymentMethod']); + } + public function testIntent() {