Luehang / react-paypal-button-v2

An easy and simple to use React button component to implement PayPal Checkout with Smart Payment Buttons V2 (Version 2).
https://luehangs.site/lue_hang/projects/react-paypal-button-v2
MIT License
275 stars 81 forks source link

[QUESTION] Payment is not being transferred #76

Open ErezShahaf opened 4 years ago

ErezShahaf commented 4 years ago

This is how I load my button

  <PayPalButton
                      amount={this.props.details.totalAmount}
                      shippingPreference="NO_SHIPPING"
                      onApprove={(data) => {
                        this.props.handlePaymentComplete(data.orderID);
                      }}
                      options={{
                        clientId: clientId,
                      }}
                    />

handlePaymentComplete - sends a request to ther back-end which then saves information to DB and validates the order.

This code seems to be working in sandbox, it shows the payment complete message, I can send a request with the orderId to paypal's api and get all the information about the transaction, the payment is in approved status, but the money won't be tranfered.

I have tried to change to live paypal, paid through my cc to my paypal seller account, my cc company sends to me an SMS about the transaction so it seems like it is doing something, the request to paypal's API says everything is ok:

{
    "id": "theorderid",
    "intent": "CAPTURE",
    "purchase_units": [
        {
            "reference_id": "default",
            "amount": {
                "currency_code": "USD",
                "value": "0.45"
            },
            "payee": {
                "email_address": "theselleremail",
                "merchant_id": "thesellersid"
            }
        }
    ],
    "payer": {
        "name": {
            "given_name": "name",
            "surname": "surname"
        },
        "email_address": "payeraddress",
        "payer_id": "payerid",
        "address": {
            "country_code": "IL"
        }
    },
    "create_time": "2020-07-23T06:35:35Z",
    "links": [
        {
            "href": "https://api.paypal.com/v2/checkout/orders/id",
            "rel": "self",
            "method": "GET"
        },
        {
            "href": "https://api.paypal.com/v2/checkout/orders/id",
            "rel": "update",
            "method": "PATCH"
        },
        {
            "href": "https://api.paypal.com/v2/checkout/orders/id/capture",
            "rel": "capture",
            "method": "POST"
        }
    ],
    "status": "APPROVED"

But,once again the payment won't actually be transferred.

I have checked the internet for answers, but couldn't find anything besides deprecated paypal versions where you had to call some kind of expressCheckout command in order to finish the transaction, so I guess the solution is something similar to that idea, but I couldn't find it.

What I have already tried to do, but did not affect anything, is to use the action.order.capture:

            <PayPalButton
              amount={this.props.details.totalAmount}
              shippingPreference="NO_SHIPPING"
              onApprove={(data, actions) => {
                actions.order.capture();
                this.props.handlePaymentComplete(data.orderID);
              }}
              options={{
                clientId: clientId,
              }}
            />
ErezShahaf commented 4 years ago

Solved: <PayPalButton amount={this.props.details.totalAmount} shippingPreference="NO_SHIPPING" onApprove={(data, actions) => { actions.order.capture().then(() => { this.props.handlePaymentComplete(data.orderID); }); }} options={{ clientId: clientId, }} />

Should have waited for actions.order.capture to end.