fix: capture one time and subscriptions separately (#38630)

This commit is contained in:
Ahmad Abdolsaheb
2020-04-24 19:57:19 +03:00
committed by GitHub
parent 11868700ad
commit a45df11de1
2 changed files with 16 additions and 7 deletions

View File

@ -42,14 +42,20 @@ export class PayPalButtonScriptLoader extends Component {
'paypal-sdk',
true,
`https://www.paypal.com/sdk/js${queries}`,
this.OnScriptLoad
this.onScriptLoad
);
}
OnScriptLoad = () => {
onScriptLoad = () => {
this.setState({ isSdkLoaded: true });
};
captureOneTimePayment(data, actions) {
return actions.order.capture().then(details => {
return this.props.onApprove(details, data);
});
}
render() {
const { isSdkLoaded, isSubscription } = this.state;
const {
@ -72,7 +78,11 @@ export class PayPalButtonScriptLoader extends Component {
<Button
createOrder={isSubscription ? null : createOrder}
createSubscription={isSubscription ? createSubscription : null}
onApprove={onApprove}
onApprove={
isSubscription
? (data, actions) => onApprove(data, actions)
: (data, actions) => this.captureOneTimePayment(data, actions)
}
onCancel={onCancel}
onError={onError}
style={style}

View File

@ -97,10 +97,9 @@ export class PaypalButton extends Component {
});
}}
isSubscription={isSubscription}
onApprove={(data, actions) => {
return actions.order.capture().then(function(data) {
this.handleApproval(data);
});
on={true}
onApprove={data => {
this.handleApproval(data);
}}
onCancel={() => {
this.props.onDonationStateChange(