Braintree信用卡和PayPal,创建新的付款方式或使用现有的

时间:2018-06-08 13:13:50

标签: php paypal braintree credit-card

我正在尝试使用Braintree进行CreditCard和PayPal交易。我已经设置了客户端,但我在服务器端集成方面遇到了一些困难。我遇到的问题是创建付款方式,但我希望它检查它是否已经存在(相同的信用卡或PayPal帐户),如果只是使用预先存在的付款方式。我目前正在检查客户是否已经存在并创建新客户或使用预先存在的客户。然后我使用paymentMethod()->create函数创建付款方式。我希望它验证卡(如果它是信用卡,但如果是PayPal则不是。)

似乎Braintree API并不是最直接的API,也不是开发人员友好的开发人员生活方式。

当前代码:

// Create the Customer
        if (Gateway::getGateway()->customerExists(Session::get("user_id"))) {
            $customerID = Session::get("user_id");
        } else {
            $result = $gateway->customer()->create([
                'email' => Session::get("user_email"),
                'firstName' => Session::get("first_name"),
                'lastName' => Session::get("last_name"),
                'id' => Session::get("user_id"),
                'riskData' => [
                    'customerIp' => RemoteAddress::getIpAddress()
                ]
            ]);

            if ($result->success) {
                $customerID = $result->customer->id;
            }
        }

        // Create payment method
        $result = $gateway->paymentMethod()->create([
            'customerId' => $customerID,
            'paymentMethodNonce' => $nonce,
            'deviceData' => $deviceData,
            'billingAddress' => [
                'countryName' => Session::get("shipping_country"),
                'extendedAddress' => Session::get("shipping_addressline2"),
                'firstName' => Session::get("first_name"),
                'lastName' => Session::get("last_name"),
                'locality' => Session::get("shipping_suburb"),
                'postalCode' => Session::get("shipping_postcode"),
                'region' => Session::get("shipping_state"),
                'streetAddress' => Session::get("shipping_addressline1")
            ],
            'options' => [
                'verifyCard' => true
            ]
        ]);

        if ($result->success) {
            $paymentMethodToken = $result->paymentMethod->token;

        } else {
            foreach($result->errors->deepAll() as $error) {
                echo 'Error: ' . $error->code . ": " . $error->message . "\n";
            }

            $verification = $result->creditCardVerification;
            echo $verification->status."\n";

            echo $verification->processorResponseCode."\n";

            echo $verification->processorResponseText."\n";

            echo $verification->gatewayRejectionReason."\n";
        }

        echo $paymentMethodToken;

感谢您的帮助。

0 个答案:

没有答案