PayPal\Api\Item::setCurrency PHP Method

setCurrency() public method

3-letter currency code.
public setCurrency ( string $currency )
$currency string
    public function setCurrency($currency)
    {
        $this->currency = $currency;
        return $this;
    }

Usage Example

 /**
  * @param PaymentInterface $payment
  */
 public function init(PaymentInterface $payment)
 {
     $credentials = new OAuthTokenCredential($this->options['client_id'], $this->options['secret']);
     $apiContext = new ApiContext($credentials);
     $apiContext->setConfig(['mode' => $this->options['mode']]);
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $amount = new Amount();
     $amount->setCurrency($this->options['currency']);
     $amount->setTotal($payment->getPaymentSum());
     $item = new Item();
     $item->setName($payment->getDescription());
     $item->setCurrency($amount->getCurrency());
     $item->setQuantity(1);
     $item->setPrice($amount->getTotal());
     $itemList = new ItemList();
     $itemList->addItem($item);
     $transaction = new Transaction();
     $transaction->setAmount($amount);
     $transaction->setDescription($payment->getDescription());
     $transaction->setItemList($itemList);
     $redirectUrls = new RedirectUrls();
     $redirectUrls->setReturnUrl($payment->getExtraData('return_url'));
     $redirectUrls->setCancelUrl($payment->getExtraData('cancel_url'));
     $paypalPayment = new Payment();
     $paypalPayment->setIntent('sale');
     $paypalPayment->setPayer($payer);
     $paypalPayment->setTransactions([$transaction]);
     $paypalPayment->setRedirectUrls($redirectUrls);
     $paypalPayment->create($apiContext);
     $payment->setExtraData('paypal_payment_id', $paypalPayment->getId());
     $payment->setExtraData('approval_link', $paypalPayment->getApprovalLink());
 }
All Usage Examples Of PayPal\Api\Item::setCurrency