Commit 4cbbe3c4 authored by Andrey Leschuk's avatar Andrey Leschuk
Browse files

Merge branch 'payment_fix' into 'master'

AV-365 редирект через window.open

See merge request avvy/frontend!76
parents 05134440 518a913d
Showing with 28 additions and 19 deletions
+28 -19
......@@ -3,7 +3,7 @@ import { Form, Message, Segment } from "semantic-ui-react";
import { connect } from "react-redux";
import { charge, error } from "../../reducers/stripe";
import { charge, error, ReturnStatus } from "../../reducers/stripe";
import "./PaymentForm.scss";
const mapStateToProps = state => state.stripe;
......@@ -13,7 +13,8 @@ const mapDispatchToProps = dispatch => ({
onSubmit: (userID, dataJson, options) =>
dispatch(charge(userID, dataJson, options)),
onSetError: (body, header) => dispatch(error(body, header)),
onClearError: () => dispatch(error())
onClearError: () => dispatch(error()),
setStatus: status => dispatch(ReturnStatus(status))
});
//import Stripe from 'stripe';
......@@ -173,22 +174,29 @@ class PaymentForm extends React.Component {
render() {
let errTag;
if (this.props.error) {
const { status, loading, error, error_message, setStatus } = this.props;
if (error) {
errTag = (
<Message negative>
<Message.Header>{this.props.error_message.header}</Message.Header>
<p>{this.props.error_message.body}</p>
<Message.Header>{error_message.header}</Message.Header>
<p>{error_message.body}</p>
</Message>
);
}
if (this.props.status !== undefined) {
if (status !== undefined) {
// открываем окно, и закрываем текущее окно
// window.open("avvyland://payment/" + this.props.status)
// window.close()
document.location.href = "avvyland://payment/" + this.props.status;
const w = window.open(
"avvyland://payment/" + status,
"_blank",
"width=0,height=0"
);
w.close();
// document.location.href = "avvyland://payment/" + status;
setStatus(undefined);
return undefined;
// return null;
}
return (
......@@ -225,7 +233,7 @@ class PaymentForm extends React.Component {
<Form.Button
fluid
primary
loading={this.props.loading}
loading={loading}
onClick={this.handleBeforeSubmit}
data-value={5}
>
......@@ -234,7 +242,7 @@ class PaymentForm extends React.Component {
<Form.Button
fluid
primary
loading={this.props.loading}
loading={loading}
onClick={this.handleBeforeSubmit}
data-value={10}
>
......@@ -243,7 +251,7 @@ class PaymentForm extends React.Component {
<Form.Button
fluid
primary
loading={this.props.loading}
loading={loading}
onClick={this.handleBeforeSubmit}
data-value={50}
>
......@@ -252,7 +260,7 @@ class PaymentForm extends React.Component {
<Form.Button
fluid
primary
loading={this.props.loading}
loading={loading}
onClick={this.handleBeforeSubmit}
data-value={100}
>
......@@ -268,7 +276,7 @@ class PaymentForm extends React.Component {
content: "Checkout",
onClick: e => this.handleBeforeSubmit(e)
}}
loading={this.props.loading}
loading={loading}
name="amount"
onChange={this.handleChange}
actionPosition="left"
......
......@@ -55,10 +55,10 @@ export const ClearError = () => ({
}
});
// const ReturnStatus = status => ({
// type: RETURN_STATUS,
// payload: status
// });
export const ReturnStatus = status => ({
type: RETURN_STATUS,
payload: status
});
/**
* Устанавливаем текст ошибки
......@@ -110,6 +110,7 @@ export const charge = (userID, jsonData, options) => dispatch => {
response.paymentIntent.status === "succeeded"
) {
// Handle successful payment here
dispatch(ReturnStatus(response.paymentIntent.status));
dispatch({
type: ACTIONS.USER.ADD_BALANCE,
payload: response.paymentIntent.amount
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment