Example #1
0
 public function actionCreate()
 {
     $productOrder = $this->getModel(Yii::$app->request->post('orderId'));
     $chargeForm = new ChargeForm();
     $chargeForm->order_no = $productOrder->id;
     $chargeForm->amount = $productOrder->payAmount;
     /**
      * @see Channel
      */
     $chargeForm->channel = Channel::ALIPAY_PC_DIRECT;
     $chargeForm->currency = 'cny';
     $chargeForm->client_ip = Yii::$app->getRequest()->userIP;
     $chargeForm->subject = sprintf("为订单ID为#%s的订单付款。", $productOrder->id);
     $chargeForm->body = sprintf('订单总价为 %s, 联系方式为 %s, 联系地址为 %s', $productOrder->total_price, $productOrder->contact, $productOrder->address);
     $chargeForm->extra = ['success_url' => Url::to(['success-sync-callback'], true)];
     if ($response = $chargeForm->create()) {
         $productOrder->out_order_no = $response->order_no;
         $productOrder->charge_id = $response->id;
         if ($productOrder->save()) {
             return $response->__toArray(true);
         }
     } elseif ($chargeForm->hasErrors()) {
         return $chargeForm->getErrors();
     }
     throw new ServerErrorHttpException();
 }
 public function testCreate()
 {
     $chargeForm = new ChargeForm();
     $chargeForm->load(require 'data/charge.php', '');
     $this->assertTrue($chargeForm->validate());
     $data = $chargeForm->create()->__toArray();
     $this->assertTrue(is_array($data));
     $reflectionClass = new ReflectionClass('\\idarex\\pingppyii2\\CodeAutoCompletion\\Charge');
     $properties = $reflectionClass->getDefaultProperties();
     $this->assertTrue(array_diff_key($data, $properties) == []);
 }
Example #3
0
 /**
  * @depends testCreate
  */
 public function testCreateWithPrivateKey()
 {
     $config = Yii::$app->getComponents()['pingpp'];
     $config['privateKey'] = file_get_contents(dirname(__FILE__) . '/rsa_private_key.pem');
     $component = Yii::createObject($config);
     $chargeForm = new ChargeForm();
     $chargeForm->component = $component;
     $chargeForm->load(require 'data/charge.php', '');
     $this->assertTrue($chargeForm->validate() && $chargeForm->create());
     $this->assertTrue(is_array($chargeForm->getCharge(true)));
 }