-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from strichliste/paypal-refinment
Paypal refinement
- Loading branch information
Showing
8 changed files
with
138 additions
and
125 deletions.
There are no files selected for viewing
24 changes: 10 additions & 14 deletions
24
src/components/currency/__tests__/__snapshots__/currency-input.spec.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,17 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`CurrencyInput matches the snapshot 1`] = ` | ||
<div> | ||
<input | ||
class="css-f1jp27" | ||
type="tel" | ||
value="0.00" | ||
/> | ||
</div> | ||
<input | ||
class="css-f1jp27" | ||
type="tel" | ||
value="0.00" | ||
/> | ||
`; | ||
|
||
exports[`CurrencyInput with a default value matches the snapshot 1`] = ` | ||
<div> | ||
<input | ||
class="css-f1jp27" | ||
type="tel" | ||
value="1,234.56" | ||
/> | ||
</div> | ||
<input | ||
class="css-f1jp27" | ||
type="tel" | ||
value="1,234.56" | ||
/> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { AcceptButton, styled } from 'bricks-of-sand'; | ||
import React from 'react'; | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
import { useSettings } from '../../store'; | ||
import { Currency, CurrencyInput } from '../currency'; | ||
import { useTransactionValidator } from '../transaction/validator'; | ||
|
||
const Wrapper = styled('div')({ | ||
form: { | ||
display: 'flex', | ||
marginBottom: '1rem', | ||
}, | ||
input: { | ||
grow: 1, | ||
marginRight: '1rem', | ||
}, | ||
}); | ||
|
||
interface Props { | ||
userName: string; | ||
userId: number; | ||
} | ||
|
||
export const PayPalTransactionForm = React.memo((props: Props) => { | ||
const settings = useSettings(); | ||
const [value, setValue] = React.useState(0); | ||
const isValid = useTransactionValidator(value, props.userId); | ||
const numberAmount = value / 100; | ||
|
||
const BASE_URL = settings.paypal.sandbox | ||
? 'https://www.sandbox.paypal.com/cgi-bin/webscr' | ||
: 'https://www.paypal.com/cgi-bin/webscr'; | ||
const returnUrl = `${location.href}/${numberAmount}`; | ||
const returnCancelUrl = location.href; | ||
const fee = numberAmount * (settings.paypal.fee / 100) || null; | ||
const amount = fee ? numberAmount + fee : numberAmount; | ||
|
||
return ( | ||
<> | ||
<Wrapper> | ||
<form action={BASE_URL} method="post"> | ||
<CurrencyInput value={value} onChange={setValue} /> | ||
<input type="hidden" name="cmd" value="_xclick" /> | ||
<input | ||
type="hidden" | ||
name="business" | ||
value={settings.paypal.recipient} | ||
/> | ||
<input | ||
type="hidden" | ||
name="item_name" | ||
value={`STRICHLISTE: ${props.userName}`} | ||
/> | ||
<input type="hidden" name="rm" value="1" /> | ||
<input type="hidden" name="no_shipping" value="1" /> | ||
<input type="hidden" name="no_note" value="1" /> | ||
<input type="hidden" name="amount" value={amount} /> | ||
<input type="hidden" name="return" value={returnUrl} /> | ||
<input type="hidden" name="cancel_return" value={returnCancelUrl} /> | ||
<input | ||
type="hidden" | ||
name="currency_code" | ||
value={settings.i18n.currency.alpha3} | ||
/> | ||
<AcceptButton disabled={!isValid} /> | ||
</form> | ||
</Wrapper> | ||
{fee && ( | ||
<p> | ||
<FormattedMessage id="PAY_PAL_FEE_LABEL" defaultMessage="fee: " /> | ||
<Currency value={fee} /> | ||
</p> | ||
)} | ||
</> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters