fix: capture one time and subscriptions separately (#38630)
This commit is contained in:
@ -42,14 +42,20 @@ export class PayPalButtonScriptLoader extends Component {
|
|||||||
'paypal-sdk',
|
'paypal-sdk',
|
||||||
true,
|
true,
|
||||||
`https://www.paypal.com/sdk/js${queries}`,
|
`https://www.paypal.com/sdk/js${queries}`,
|
||||||
this.OnScriptLoad
|
this.onScriptLoad
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
OnScriptLoad = () => {
|
onScriptLoad = () => {
|
||||||
this.setState({ isSdkLoaded: true });
|
this.setState({ isSdkLoaded: true });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
captureOneTimePayment(data, actions) {
|
||||||
|
return actions.order.capture().then(details => {
|
||||||
|
return this.props.onApprove(details, data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { isSdkLoaded, isSubscription } = this.state;
|
const { isSdkLoaded, isSubscription } = this.state;
|
||||||
const {
|
const {
|
||||||
@ -72,7 +78,11 @@ export class PayPalButtonScriptLoader extends Component {
|
|||||||
<Button
|
<Button
|
||||||
createOrder={isSubscription ? null : createOrder}
|
createOrder={isSubscription ? null : createOrder}
|
||||||
createSubscription={isSubscription ? createSubscription : null}
|
createSubscription={isSubscription ? createSubscription : null}
|
||||||
onApprove={onApprove}
|
onApprove={
|
||||||
|
isSubscription
|
||||||
|
? (data, actions) => onApprove(data, actions)
|
||||||
|
: (data, actions) => this.captureOneTimePayment(data, actions)
|
||||||
|
}
|
||||||
onCancel={onCancel}
|
onCancel={onCancel}
|
||||||
onError={onError}
|
onError={onError}
|
||||||
style={style}
|
style={style}
|
||||||
|
@ -97,10 +97,9 @@ export class PaypalButton extends Component {
|
|||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
isSubscription={isSubscription}
|
isSubscription={isSubscription}
|
||||||
onApprove={(data, actions) => {
|
on={true}
|
||||||
return actions.order.capture().then(function(data) {
|
onApprove={data => {
|
||||||
this.handleApproval(data);
|
this.handleApproval(data);
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
onCancel={() => {
|
onCancel={() => {
|
||||||
this.props.onDonationStateChange(
|
this.props.onDonationStateChange(
|
||||||
|
Reference in New Issue
Block a user