Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for currency with pronamic_pay_currency field name or option. #21

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ it requires the `pronamic_pay_amount` option:
[number pronamic_pay_amount]
```

## Currency

Payments are created with the Euro currency by default. An ISO 4217 currency code can be provided
using the `pronamic_pay_currency` field name or as a field option:

```
[hidden pronamic_pay_currency "CHF"]

[select select-123 pronamic_pay_currency "EUR" "CHF"]
```

## WordPress environment for building and testing

```
Expand All @@ -35,3 +46,4 @@ skip_mail: on
- https://wordpress.org/plugins/cf7-conditional-fields/
- https://contactform7.com/
- https://contactform7.com/tag-syntax/
- https://en.wikipedia.org/wiki/ISO_4217#List_of_ISO_4217_currency_codes
9 changes: 8 additions & 1 deletion src/Pronamic.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,14 @@ public static function get_submission_payment( WPCF7_Submission $submission ) {
$submission_helper = new SubmissionHelper( $submission );

// Total.
$total = new Money();
$currency = \strtoupper( $submission_helper->get_value_by_tag_name_or_option( 'pronamic_pay_currency' ) );

if ( '' === $currency ) {
$currency = 'EUR';
}

$total = new Money( 0, $currency );

$parser = new Parser();

$tags = $submission_helper->get_tags_with_basetype_or_name_or_option( 'pronamic_pay_amount' );
Expand Down