예제 #1
0
 public function testCreate()
 {
     $creditCard = new CreditCard();
     $creditCard->setName('John Doe');
     $creditCard->setZip5('90210');
     $creditCard->setNumber('4242424242424242');
     $creditCard->setCvc('123');
     $creditCard->setExpirationMonth('1');
     $creditCard->setExpirationYear('2020');
     $chargeRequest = new ChargeRequest();
     $chargeRequest->setCreditCard($creditCard);
     $chargeRequest->setAmount(2000);
     $chargeRequest->setCurrency('usd');
     $chargeRequest->setDescription('*****@*****.**');
     $this->assertEntityValid($chargeRequest);
     $this->assertSame(2000, $chargeRequest->getAmount());
     $this->assertSame('usd', $chargeRequest->getCurrency());
     $this->assertSame('*****@*****.**', $chargeRequest->getDescription());
     $this->assertTrue($chargeRequest->getCreditCard() instanceof CreditCard);
 }
 public function testGetCharge()
 {
     $creditCard = new CreditCard();
     $creditCard->setName('John Doe');
     $creditCard->setZip5('90210');
     $creditCard->setNumber('4242424242424242');
     $creditCard->setCvc('123');
     $creditCard->setExpirationMonth('1');
     $creditCard->setExpirationYear('2020');
     $chargeRequest = new ChargeRequest();
     $chargeRequest->setCreditCard($creditCard);
     $chargeRequest->setAmount(2000);
     $chargeRequest->setCurrency('usd');
     $chargeRequest->setDescription('*****@*****.**');
     $paymentGateway = new FakePaymentGateway();
     $charge = $paymentGateway->getCharge($chargeRequest);
     $this->assertSame(2000, $charge->getAmount());
     $this->assertSame('usd', $charge->getCurrency());
     $this->assertSame('*****@*****.**', $charge->getDescription());
     $this->assertSame('ch_xxxxxxxxxxxxxx', $charge->getExternalId());
     $this->assertSame('4242', $charge->getLast4());
     $this->assertTrue($charge->getCreated() > 0);
 }
예제 #3
0
 /**
  * @param Order $order
  * @param CreditCard $creditCard
  * @param int $amount
  */
 public function addCreditCardPayment(Order $order, CreditCard $creditCard, $amount)
 {
     $chargeRequest = new ChargeRequest();
     $chargeRequest->setCreditCard($creditCard);
     $chargeRequest->setAmount($amount);
     $chargeRequest->setCurrency('usd');
     $chargeRequest->setDescription($order->getShippingAddress()->getEmail());
     $chargeResponse = $this->paymentGateway->getCharge($chargeRequest);
     $payment = new CreditPayment($chargeResponse);
     $this->throwValidationErrors($payment);
     $order->addPayment($payment);
 }