简体   繁体   中英

Paypal Billing agreement, weird response

I have an issue dealing with the PayPal-PHP-SDK,

My problem is, i'm creating the plan and the agreement, everything is working fine,

I'm putting 30€ as a fee in the agreement and the plan :

        $amont = 30 ;   // Prix 
$merchantPreferences->setReturnUrl("$baseUrl/paiement-accept.php")
    ->setCancelUrl("$baseUrl/paiement-cancel.php")
    ->setAutoBillAmount("yes")
    ->setInitialFailAmountAction("CONTINUE")
    ->setMaxFailAttempts("0")
    ->setSetupFee(new Currency(array('value' => $amont, 'currency' => $currency)));

The date i'm using to create it it's :

$date = date('Y-m-d\TH:i:s', time()+210)  ."Z";`
$agreement->setName($name)
    ->setDescription($description)
    ->setStartDate($date);

I tried with time()+210 and using only now's timestamp.

I execute the agreement, and there is the answer :

{
"id": "I-VD24XJ8MG14N",
"state": "Pending",
"description": "Abonnement Mensuel - 30\u20ac/mois",
"plan": {
    "payment_definitions": [
        {
            "type": "REGULAR",
            "frequency": "Month",
            "amount": {
                "currency": "EUR",
                "value": "30.00"
            },
            "cycles": "0",
            "charge_models": [
                {
                    "type": "TAX",
                    "amount": {
                        "currency": "EUR",
                        "value": "0.00"
                    }
                },
                {
                    "type": "SHIPPING",
                    "amount": {
                        "currency": "EUR",
                        "value": "0.00"
                    }
                }
            ],
            "frequency_interval": "1"
        }
    ],
    "merchant_preferences": {
        "setup_fee": {
            "currency": "EUR",
            "value": "0.00"
        },
        "max_fail_attempts": "0",
        "auto_bill_amount": "YES"
    }
},
"links": [
    {
        "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-VD24XJ8MG14N/suspend",
        "rel": "suspend",
        "method": "POST"
    },
    {
        "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-VD24XJ8MG14N/re-activate",
        "rel": "re_activate",
        "method": "POST"
    },
    {
        "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-VD24XJ8MG14N/cancel",
        "rel": "cancel",
        "method": "POST"
    },
    {
        "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-VD24XJ8MG14N/bill-balance",
        "rel": "self",
        "method": "POST"
    },
    {
        "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-VD24XJ8MG14N/set-balance",
        "rel": "self",
        "method": "POST"
    }
],
"start_date": "2014-11-21T23:00:00Z",
"agreement-details": {
    "outstanding_balance": {
        "currency": "EUR",
        "value": "0.00"
    },
    "cycles_remaining": "0",
    "cycles_completed": "0",
    "final_payment_date": "1970-01-01T00:00:00Z",
    "failed_payment_count": "0"
}

}

I don't know why the setup_fees are at 00

Why is start date at "2014-11-21T23:00:00Z"

And why is it the state Pending.

Can you help me how to make it work ? :(

If you need more informations (more code) to see where the problem is, ask me and i'll answer with more informations

Thanks a lot !

Xusifob

/***************************************************************************************************

EDIT :

****************************************************************************************************/

Thank you for taking the time of answering me.

For the date i changed it,

The payment method to create the billing agrement is a paypal account :

// Add Payer
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$agreement->setPayer($payer);

I've already done all theses steps, click on the approval url, connect to my paypal test account and accept the transaction.

On my return page, I am on this page :

mywebsite/paiement-accept.php?token=EC-4VW6406102605853H

I've seen in the Paypal api that the ExecuteAgreement page is expecting a success value in the url ($_GET['success'] = true)

But i never got this value in my url, and the answer tell me that the User cancelled the Approval.

I changed the code not to have this error anymore and it gives me the response i put above.

This is my code :

$createdAgreement = require '../vendor/paypal/rest-api-sdk-php/sample/billing/ExecuteAgreement.php';
require '../vendor/paypal/rest-api-sdk-php/sample/billing/GetBillingAgreement.php';

And for the ExecuteAgreement :

if (isset($_GET['token'])) {

    $token = $_GET['token'];

    $agreement = new \PayPal\Api\Agreement();

    try {
        $agreement->execute($token, $apiContext);
    } catch (Exception $ex) {
        ResultPrinter::printError("Executed an Agreement", "Agreement", $agreement->getId(), $_GET['token'], $ex);
        exit(1);
    }
    ResultPrinter::printResult("Executed an Agreement", "Agreement", $agreement->getId(), $_GET['token'], $agreement);

} else {
    ResultPrinter::printResult("User Cancelled the Approval", null);
}
return $agreement;

Changing the date did not solve the problem with the start_date response issue

Thank you again for your help :)

For the date, you could use date('c', time()+210) as per http://php.net/manual/en/function.date.php

Would you mind answering the information as, what was the payment method while creating Billing Agrement. If you used PayPal, you need to click on the approval_url, and complete the flow.

Once done, you need to execute the payment, and then, when you do a get on the Agreement, you would be able to see the state as Active.

Let me know if that fixes this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM