Skip to content

Commit

Permalink
feature #348 Added payment instructions to PaymentMethodView ()
Browse files Browse the repository at this point in the history
This PR was merged into the 1.0-dev branch.

Discussion
----------

To be able to show payment instructions by using Shop-API, I added the needed fields to the view and factory.

Commits
-------

183f2c1 Added payment instructions to PaymentMethodView
aad4772 Fixed tests
f63d2ad Fixed unit-tests
6053084 Updated reponses for unit tests
  • Loading branch information
lchrusciel authored Jan 4, 2019
2 parents bc73791 + 6053084 commit 84dc0a8
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 8 deletions.
2 changes: 2 additions & 0 deletions spec/Factory/PaymentMethodViewFactorySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ function it_build_payment_method_view(PaymentMethodInterface $paymentMethod, Pay

$paymentMethodTranslation->getName()->willReturn('Cash on delivery');
$paymentMethodTranslation->getDescription()->willReturn('Really nice payment method');
$paymentMethodTranslation->getInstructions()->willReturn('Put the money in this bag, right here!');

$paymentMethodView = new PaymentMethodView();

$paymentMethodView->code = 'COD_CODE';
$paymentMethodView->name = 'Cash on delivery';
$paymentMethodView->description = 'Really nice payment method';
$paymentMethodView->instructions = 'Put the money in this bag, right here!';

$this->create($paymentMethod, 'en_GB')->shouldBeLike($paymentMethodView);
}
Expand Down
9 changes: 6 additions & 3 deletions src/Factory/PaymentMethodViewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ public function create(PaymentMethodInterface $paymentMethod, string $locale): P
/** @var PaymentMethodView $paymentMethodView */
$paymentMethodView = new $this->paymentMethodViewClass();

$paymentMethodView->code = $paymentMethod->getCode();
$paymentMethodView->name = $paymentMethod->getTranslation($locale)->getName();
$paymentMethodView->description = $paymentMethod->getTranslation($locale)->getDescription();
$translation = $paymentMethod->getTranslation($locale);

$paymentMethodView->code = $paymentMethod->getCode() ?? '';
$paymentMethodView->name = $translation->getName() ?? '';
$paymentMethodView->description = $translation->getDescription() ?? '';
$paymentMethodView->instructions = $translation->getInstructions() ?? '';

return $paymentMethodView;
}
Expand Down
3 changes: 3 additions & 0 deletions src/View/PaymentMethodView.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ class PaymentMethodView

/** @var string */
public $description;

/** @var string */
public $instructions;
}
2 changes: 2 additions & 0 deletions tests/DataFixtures/ORM/payment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ Sylius\Component\Payment\Model\PaymentMethodTranslation:
name: 'Cash on delivery'
locale: 'en_GB'
description: <paragraph(2)>
instructions: "Please put the money in the bag!"
translatable: "@cash_on_delivery"
pay_by_check_translation:
name: 'Pay by check'
locale: 'en_GB'
description: <paragraph(2)>
instructions: "Please put the money in the bag!"
translatable: "@pay_by_check"
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@
"method": {
"code": "PBC",
"name": "Pay by check",
"description": "@string@"
"description": "@string@",
"instructions": "@string@"
},
"price": {
"current": 11495,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
"COD": {
"code": "COD",
"name": "Cash on delivery",
"description": "@string@"
"description": "@string@",
"instructions": "@string@"
},
"PBC": {
"code": "PBC",
"name": "Pay by check",
"description": "@string@"
"description": "@string@",
"instructions": "@string@"
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Responses/Expected/order/order_details_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
"method": {
"code": "PBC",
"name": "Pay by check",
"description": @string@
"description": @string@,
"instructions": @string@
},
"price": {
"current": 5498,
Expand Down
3 changes: 2 additions & 1 deletion tests/Responses/Expected/order/orders_list_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@
"method": {
"code": "PBC",
"name": "Pay by check",
"description": @string@
"description": @string@,
"instructions": @string@
},
"price": {
"current": 5498,
Expand Down

0 comments on commit 84dc0a8

Please sign in to comment.