应用优惠券时条纹不订阅计划

时间:2017-06-29 06:37:39

标签: php stripe-payments stripe-connect

我已经包含Stripe库来创建订阅。它运行正常但是当应用优惠券时,条带客户对象不会返回订阅对象,也不会在条带仪表板中创建订阅。

我正在使用以下代码:

\Stripe::setApiKey('my_stripe_secret_key');
$cardDeclined = false;
try {
    // Use Stripe's bindings...
    // Create customer with card, plan, qty, and contact details
    if ($coupon) {
        $customer_array = array(
            "card" => $token,
            "plan" => $plan,
            "quantity" => $qty,
            "email" => $email,
            "coupon" => $coupon,
            "description" => $fname . " " . $lname
        );
    }else{
        $customer_array = array(
            "card" => $token,
            "plan" => $plan,
            "quantity" => $qty,
            "email" => $email,
            "description" => $fname . " " . $lname
        );
    }
    $customer = \Stripe_Customer::create($customer_array);

    echo "<pre>";
    print_r($customer);
    echo "</pre>";

    $planamt = 10;
    $planinterval = "month";
    if ($planinterval == "year") {
        $planamt = number_format($planamt / 12);
        $planinterval = $planinterval . " x 12 months";
    }

    // return "receipt" to client and email it
    $from = "noreply@mysite.com";
    $subject = "Thanks for your purchase";
    $message = $this->_getEmailMessage($customer, $planamt, $planinterval, $discount);

    $headers = "From: Admin <" . $from . ">\r\n";
    $headers .= "Reply-To: " . $from . "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    $headers .= "Bcc: sales@mysite.com\r\n";  // uncomment for production

    mail($email, $subject, $message, $headers);

} catch( \Stripe_CardError $e) {
    // Since it's a decline, Stripe_CardError will be caught
    $body = $e->getJsonBody();
    $err  = $body['error'];

    $error = $e;
    $this->returnJson(array('success' => 0, 'error' => $error));
    $cardDeclined = true;
} catch ( \Stripe_InvalidRequestError $e ) {
    // Invalid parameters were supplied to Stripe's API
    $error = $e;
    $this->returnJson(array('success' => 0, 'error' => $error));
} catch ( \Stripe_AuthenticationError $e ) {
    // Authentication with Stripe's API failed
    // (maybe you changed API keys recently)
    $error = $e;
    $this->returnJson(array('success' => 0, 'error' => $error));
} catch (\Stripe_ApiConnectionError $e) {
    // Network communication with Stripe failed
    $error = $e;
    $this->returnJson(array('success' => 0, 'error' => $error));
} catch ( \Stripe_Error $e ) {
    // Display a very generic error to the user, and maybe send
    // yourself an email
    $error = $e;
    $this->returnJson(array('success' => 0, 'error' => $error));
} catch ( \Exception $e ) {
    // Something else happened, completely unrelated to Stripe
    $error = $e;
    $this->returnJson(array('success' => 0, 'error' => $error));
}

返回以下内容:

 Stripe_Customer Object
(
    [_apiKey:protected] => my_stripe_secret_key
    [_values:protected] => Array
        (
            [id] => cus_AvngFkp4jfm1r7
            [object] => customer
            [account_balance] => 0
            [created] => 1498717473
            [currency] => usd
            [default_source] => card_1AZw4pFdHoCs9Gf5GuLjl3nq
            [delinquent] => 
            [description] => name
            [discount] => Stripe_Object Object
                (
                    [_apiKey:protected] => my_stripe_secret_key
                    [_values:protected] => Array
                        (
                            [object] => discount
                            [coupon] => Stripe_Object Object
                                (
                                    [_apiKey:protected] => my_stripe_secret_key
                                    [_values:protected] => Array
                                        (
                                            [id] => coupon20
                                            [object] => coupon
                                            [amount_off] => 2000
                                            [created] => 1498652592
                                            [currency] => usd
                                            [duration] => forever
                                            [duration_in_months] => 
                                            [livemode] => 
                                            [max_redemptions] => 
                                            [metadata] => Array
                                                (
                                                )

                                            [percent_off] => 
                                            [redeem_by] => 
                                            [times_redeemed] => 18
                                            [valid] => 1
                                        )

                                    [_unsavedValues:protected] => Stripe_Util_Set Object
                                        (
                                            [_elts:Stripe_Util_Set:private] => Array
                                                (
                                                )

                                        )

                                    [_transientValues:protected] => Stripe_Util_Set Object
                                        (
                                            [_elts:Stripe_Util_Set:private] => Array
                                                (
                                                )

                                        )

                                    [_retrieveOptions:protected] => Array
                                        (
                                        )

                                )

                            [customer] => cus_AvngFkp4jfm1r7
                            [end] => 
                            [start] => 1498717473
                            [subscription] => 
                        )

                    [_unsavedValues:protected] => Stripe_Util_Set Object
                        (
                            [_elts:Stripe_Util_Set:private] => Array
                                (
                                )

                        )

                    [_transientValues:protected] => Stripe_Util_Set Object
                        (
                            [_elts:Stripe_Util_Set:private] => Array
                                (
                                )

                        )

                    [_retrieveOptions:protected] => Array
                        (
                        )

                )

            [email] => testmail@gmail.com
            [livemode] => 
            [metadata] => Array
                (
                )

            [shipping] => 
            [sources] => Stripe_List Object
                (
                    [_apiKey:protected] => my_stripe_secret_key
                    [_values:protected] => Array
                        (
                            [object] => list
                            [data] => Array
                                (
                                    [0] => Stripe_Object Object
                                        (
                                            [_apiKey:protected] => my_stripe_secret_key
                                            [_values:protected] => Array
                                                (
                                                    [id] => card_1AZw4pFdHoCs9Gf5GuLjl3nq
                                                    [object] => card
                                                    [address_city] => 
                                                    [address_country] => 
                                                    [address_line1] => 
                                                    [address_line1_check] => 
                                                    [address_line2] => 
                                                    [address_state] => 
                                                    [address_zip] => 
                                                    [address_zip_check] => 
                                                    [brand] => Visa
                                                    [country] => US
                                                    [customer] => cus_AvngFkp4jfm1r7
                                                    [cvc_check] => pass
                                                    [dynamic_last4] => 
                                                    [exp_month] => 12
                                                    [exp_year] => 2020
                                                    [fingerprint] => f7vYSiCeMLGo8bJp
                                                    [funding] => credit
                                                    [last4] => 4242
                                                    [metadata] => Array
                                                        (
                                                        )

                                                    [name] => 
                                                    [tokenization_method] => 
                                                )

                                            [_unsavedValues:protected] => Stripe_Util_Set Object
                                                (
                                                    [_elts:Stripe_Util_Set:private] => Array
                                                        (
                                                        )

                                                )

                                            [_transientValues:protected] => Stripe_Util_Set Object
                                                (
                                                    [_elts:Stripe_Util_Set:private] => Array
                                                        (
                                                        )

                                                )

                                            [_retrieveOptions:protected] => Array
                                                (
                                                )

                                        )

                                )

                            [has_more] => 
                            [total_count] => 1
                            [url] => /v1/customers/cus_AvngFkp4jfm1r7/sources
                        )

                    [_unsavedValues:protected] => Stripe_Util_Set Object
                        (
                            [_elts:Stripe_Util_Set:private] => Array
                                (
                                )

                        )

                    [_transientValues:protected] => Stripe_Util_Set Object
                        (
                            [_elts:Stripe_Util_Set:private] => Array
                                (
                                )

                        )

                    [_retrieveOptions:protected] => Array
                        (
                        )

                )

            [subscriptions] => Stripe_List Object
                (
                    [_apiKey:protected] => my_stripe_secret_key
                    [_values:protected] => Array
                        (
                            [object] => list
                            [data] => Array
                                (
                                )

                            [has_more] => 
                            [total_count] => 0
                            [url] => /v1/customers/cus_AvngFkp4jfm1r7/subscriptions
                        )

                    [_unsavedValues:protected] => Stripe_Util_Set Object
                        (
                            [_elts:Stripe_Util_Set:private] => Array
                                (
                                )

                        )

                    [_transientValues:protected] => Stripe_Util_Set Object
                        (
                            [_elts:Stripe_Util_Set:private] => Array
                                (
                                )

                        )

                    [_retrieveOptions:protected] => Array
                        (
                        )

                )

        )

    [_unsavedValues:protected] => Stripe_Util_Set Object
        (
            [_elts:Stripe_Util_Set:private] => Array
                (
                )

        )

    [_transientValues:protected] => Stripe_Util_Set Object
        (
            [_elts:Stripe_Util_Set:private] => Array
                (
                )

        )

    [_retrieveOptions:protected] => Array
        (
        )

)

代码中是否有任何遗漏或做错了? 请帮忙

0 个答案:

没有答案