从条纹结帐中获取持卡人姓名的任何方法?

时间:2019-07-16 21:54:29

标签: php stripe-payments

使用条纹结帐时如何获得持卡人的名字?客户对象的name字段不包含任何名称。是null

这是我的代码,在结帐成功时会收到条带pingback。

public function checkoutSuccessWebhook(Request $request, Response $response, array $args) {
        $this->container->logger->info("Recieved pingback from stripe");

        \Stripe\Stripe::setApiKey($this->container->settings["stripe"]["api_key"]);
        $endpoint_secret = $this->container->settings["stripe"]["api_secret"];

        $payload = @file_get_contents('php://input');
        $sig_header = isset($_SERVER['HTTP_STRIPE_SIGNATURE']) ? $_SERVER['HTTP_STRIPE_SIGNATURE'] : null;
        $event = null;

        try {
            $event = \Stripe\Webhook::constructEvent($payload, $sig_header, $endpoint_secret);
        } catch(\UnexpectedValueException $e) {
            $this->container->logger->critical($e);
            return $response->withStatus(400);
        } catch(\Stripe\Error\SignatureVerification $e) {
            $this->container->logger->critical($e);
            return $response->withStatus(400);
        }

        if ($event->type == 'checkout.session.completed') {
            $this->container->logger->info("Processing checkout.session.complete");

            $session = $event->data->object;
            $clientReferenceID = ($session && isset($session["client_reference_id"])) ? $session["client_reference_id"] : NULL;
            $customerRef = ($session && isset($session["customer"])) ? $session["customer"] : NULL;

            $product = $this->container->db->getAudioProductBySlug($clientReferenceID);
            $customer = \Stripe\Customer::retrieve($customerRef);

            $this->container->logger->debug($customer);

            $downloadToken = substr("abcdefghijklmnopqrstuvwxyz", mt_rand(0, 51), 1) . substr(md5(time()), 1);

            if(!$product || !$customer || !$session["client_reference_id"]) {
                $this->container->logger->critical($session);
                return $response->withStatus(400);
            }

            $this->container->logger->info("Inserting audio purchase ...");

            try {
                $this->container->db->insertAudioPurchase(
                    $product["id"],
                    $customer["email"],
                    $customer["name"], // NULL?
                    $session["customer"],
                    $downloadToken
                );
            } catch (\Exception $e) {
                $this->container->logger->critical($e);
                return $response->withStatus(400);
            }

            $this->container->logger->info("Sending email via SendGrid");

            try {
                $result = $this->container->SendMail->send(
                    $this->container->settings["email"]["from_name"],
                    $this->container->settings["email"]["from_address"],
                    "XXXXXX: Your Download is Ready!",
                    $customer["name"],
                    $customer["email"],
                    "Your download link expires in 7 days: <a href=\"https://XXXXXX/download/{$downloadToken}\">https://XXXXXXxx/download/{$downloadToken}</a>",
                    "Your download link expires in 7 days: https://xxxxxxx/download/{$downloadToken}"
                );
            } catch (\Exception $e) {
                $this->container->logger->error($e);
                return $response->withStatus(500);
            }


            if(!$result) {
                $this->container->logger->info("Failed to send email");
                return $response->withStatus(500);
            }

            return $response->withStatus(200);
        }
    }
}

如果我在条纹仪表板上查看交易,我可以看到客户名称,但在文档中找不到任何内容来显示如何:https://stripe.com/docs/api/customers/object ...它还将name列为{{ 1}}。

0 个答案:

没有答案