简体   繁体   English

如何自定义PayPal的结帐页面(PayPal-PHP-SDK)

[英]How to customize the checkout page of PayPal (PayPal-PHP-SDK)

I am working with the PayPal-PHP-SDK as suggested in the Developer Docs. 我正在按照开发人员文档中的建议使用PayPal-PHP-SDK。 I am running this code currently: 我目前正在运行以下代码:

http://paypal.github.io/PayPal-PHP-SDK/ http://paypal.github.io/PayPal-PHP-SDK/

I simply want to change the Brand Name and add a Logo, but I don't know how to achieve this. 我只是想更改品牌名称并添加徽标,但是我不知道该如何实现。

Since PayPal updated their Design the Design changes you can make in the profile Settings wont work anymore. 由于贝宝(PayPal)更新了其设计(Design),因此您可以在配置文件中进行的设计更改(Settings)将不再起作用。

To change the Design, you need to create a WebProfile first: 要更改设计,您需要首先创建一个WebProfile:

    // Create the WebProfile
    $presentation = new Presentation();
    $presentation->setLogoImage("http://www.yeowza.com/favico.ico")
        ->setBrandName("YeowZa! Paypal")
        ->setLocaleCode("US");
    $inputFields = new InputFields();
    $inputFields->setAllowNote(true)
        ->setNoShipping(1)
        ->setAddressOverride(0);
    $webProfile = new WebProfile();
    $webProfile->setName("YeowZa! T-Shirt Shop" . uniqid())
        ->setPresentation($presentation)
        ->setInputFields($inputFields);
    try {
        $createdProfile = $webProfile->create($paypal);
        $createdProfileID = json_decode($createdProfile);
        $profileid = $createdProfileID->id;
    } catch(PayPal\Exception\PayPalConnectionException $pce) {
        echo '<pre>',print_r(json_decode($pce->getData())),"</pre>";
        exit;
    }

The ID of the created Profile is been stored in $profileid.This ID needs to be set via. 创建的个人资料的ID存储在$ profileid中。此ID需要通过设置。 setExperienceProfileId($profileid) if you create the payment. setExperienceProfileId($ profileid)(如果创建付款)。

        // Create the Payment       
    $product = $_POST['product'];
    $price = 4;
    $shipping  = 2;
    $total = $price + $shipping;

    $payer = new Payer(); 
    $payer->setPaymentMethod("paypal");

    $item1 = new Item();
    $item1->setName('Ground Coffee 40 oz') ->setCurrency('EUR') ->setQuantity(1) ->setSku("123123")->setPrice(6.5); // Similar to `item_number` in Classic API 
    $item2 = new Item();
    $item2->setName('Granola bars') ->setCurrency('EUR') ->setQuantity(1) ->setSku("321321")->setPrice(1.5); // Similar to `item_number` in Classic API  
    $itemList = new ItemList(); 
    $itemList->setItems(array($item1, $item2));

    $details = new Details(); 
    $details->setShipping(1.2) ->setTax(1.3) ->setSubtotal(8);

    $amount = new Amount();
    $amount->setCurrency("EUR") ->setTotal(10.5) ->setDetails($details);

    $transaction = new Transaction();
    $transaction->setAmount($amount)->setItemList($itemList)->setDescription("Payment description")->setInvoiceNumber(uniqid());

    $baseUrl = "http://localhost/abiunity/test.php"; 
    $redirectUrls = new RedirectUrls(); 
    $redirectUrls->setReturnUrl($baseUrl."?success=true")->setCancelUrl($baseUrl."?success=false");

    $payment = new Payment(); 
    $payment->setExperienceProfileId($profileid)->setIntent("sale") ->setPayer($payer) ->setRedirectUrls($redirectUrls) ->setTransactions(array($transaction));
    //$request = clone $payment;

    try {
        $payment->create($paypal);
        $approvalUrl = $payment->getApprovalLink();
        header("Location:".$approvalUrl);
        exit;
    } catch(PayPal\Exception\PayPalConnectionException $pce) {
        echo '<pre>',print_r(json_decode($pce->getData())),"</pre>";
        exit;
    }

I hope this helps someone and saves a little bit of time :) 我希望这可以帮助某人并节省一些时间:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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