Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add Items to the Paypal API Dynamically ? #140

Open
tanmayapatra09 opened this issue Mar 12, 2018 · 1 comment
Open

How to add Items to the Paypal API Dynamically ? #140

tanmayapatra09 opened this issue Mar 12, 2018 · 1 comment

Comments

@tanmayapatra09
Copy link

		        $item2 = Paypalpayment::item();
		        $item2->setName('Granola bars')
		                ->setDescription('Granola Bars with Peanuts')
		                ->setCurrency('USD')
		                ->setQuantity(5)
		                ->setTax(0.2)
		                ->setPrice(2);

My Problem is I want to make this Array Dynamic. When I insert this code in a loop it shows me error. Please suggest me a process

@binitghetiya
Copy link

binitghetiya commented Mar 12, 2018

I would do something like below :)

           $all_items_arr = [];
           foreach ($items as $addon) {
                $addon_item = Paypalpayment::item();
                $addon_item->setName($addon['title'])
                        ->setDescription($addon['title'])
                        ->setCurrency($addon['currency'])
                        ->setQuantity($addon['qty'])
                        ->setTax($addon['tax'])
                        ->setPrice((float) $addon['price']);
                $all_items_arr[] = $addon_item;
            }
            $itemList = Paypalpayment::itemList();
            $itemList->setItems($all_items_arr);
    
        //transaction object
        $transaction = Paypalpayment::transaction();
        $transaction->setAmount($amount) //here amount will be total amount including tax
                ->setItemList($itemList)
                ->setDescription("Payment description")
                ->setInvoiceNumber(uniqid());
        $payment = Paypalpayment::payment();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants